For loop in a label not working!

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Yuvan raj
Regular
Posts: 38
Joined: Wed Feb 17, 2021 11:24 am
Contact:

For loop in a label not working!

#1 Post by Yuvan raj »

Hello, I created a list of different arrows ($ fightArrowActive = ["arrow_up_active", "arrow_right_active", "arrow_down_active", "arrow_left_active"]). I want to display several different arrows. I have 2 random variables. one decides how many arrows to be displayed and other which arrows to be displayed. Something like the picture below.
Image
But, I'm getting an error saying Image
And this is my arrow names
Image
Is my code correct? What mistake am I making? Thank you very much in advance guys!

This is the script.rpy

Code: Select all

define e = Character("Eileen")

$ fightArrowActive = ["arrow_up_active", "arrow_right_active", "arrow_down_active", "arrow_left_active"]

default single_sequence_arrow_list = []

label start:

    scene bg room

    call arrowlabel

    "shsjdsfffffffffffffffffffffff"

    "jiommmmmmmmmmmop;jjjjjjjjjjjjjj"

    "shsjdsfffffffffffffffffffffff"

    "jiommmmmmmmmmmop;jjjjjjjjjjjjjj"

    "shsjdsfffffffffffffffffffffff"

    "jiommmmmmmmmmmop;jjjjjjjjjjjjjj"

    "shsjdsfffffffffffffffffffffff"

    "jiommmmmmmmmmmop;jjjjjjjjjjjjjj"

    return
And this is the label and screens code:

Code: Select all

label arrowlabel:

    $ tmpInt = renpy.random.randint(3, 7) ##  This is for deciding the number of arrows on screen


    for j in range(1, tmpInt):

        $ singletmpInt = renpy.random.randint(0, 3)  ##   This is for randomly choosing the arrows names from the fightArrowIdle List.

        $ arrow_for_list = "fightArrowIdle[singletmpInt]"   ##  The value gets changed for every loop and the last arrow will be inside arrow_for_list at the end of loop

        $ single_sequence_arrow_list.append("fightArrowIdle[singletmpInt]")   ##   I append the random arrows one by one to the empty list

    if "arrow_for_list" == "single_sequence_arrow_list[3]":  ##  This is for testing whether my code is correct. If I change the number in the box bracket. Only '3' should display the text 'they match'
        text "they match"
    else:
        text "they don't"

    show screen circlescreen
    return

screen arrowscreen():

    hbox:
        xalign 0.5
        yalign 0.8

        for i in single_sequence_arrow_list:  ##   This is to show the arrows as button

                imagebutton:
                    idle single_sequence_arrow_list[i]
                    action NullAction()


User avatar
mavyxdawn
Regular
Posts: 72
Joined: Sun Dec 20, 2015 6:18 pm
Github: mavyxdawn
itch: zeillearnings
Discord: _zeil
Contact:

Re: For loop in a label not working!

#2 Post by mavyxdawn »

Hi! I found here that for loop is not supported in Ren'Py:
https://www.renpy.org/doc/html/conditio ... -statement
Ren'Py does not have continue, break, or for statements. Continue and break statements can be replaced by jumps to labels placed before or after the while loop, respectively. The first example of a while loop, above, shows how a while loop can replace a simple for statement. The second shows how it can replace a for statement which iterates through a list (also known as a foreach statement in other programming languages).
YouTube: Zeil Learnings
itch.io: Zeil Learnings

Image

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2400
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: For loop in a label not working!

#3 Post by Ocelot »

... or you can simply move for loop declaration within Python block since all you do in loop body is Python statements
< < insert Rick Cook quote here > >

User avatar
mavyxdawn
Regular
Posts: 72
Joined: Sun Dec 20, 2015 6:18 pm
Github: mavyxdawn
itch: zeillearnings
Discord: _zeil
Contact:

Re: For loop in a label not working!

#4 Post by mavyxdawn »

Oh! That makes more sense! Thank you
YouTube: Zeil Learnings
itch.io: Zeil Learnings

Image

Post Reply

Who is online

Users browsing this forum: Andredron