For loop exiting prematurely [solved]

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
User avatar
aegis-of-justice
Newbie
Posts: 9
Joined: Sun Sep 15, 2013 12:47 pm
Location: First in the the online user list!
Contact:

For loop exiting prematurely [solved]

#1 Post by aegis-of-justice »

I have a list of labels I want to call, and made a for loop. But once it's done running the first called label, the loop skips the remaining code block and exits. Am I using a wrong return statement or something? I was also having trouble running a for loop without making it a python block. If there's a way to do it with renpy, please let me know.

Thanks in advance!

Code: Select all

init python:
    chapters = [
        ("Prologue", "prologue"),
        ("Chapter 1", "chapter1"),
        ("Epilogue", "epilogue")
        ]

label play:
    python:
        for label in chapters:
            renpy.call(label)
            #only prologue label gets run
            #code exits here straight to where play is called and continues normally
            renpy.say("","Hello world.") #This doesn't show up
    return

label prologue:
    "This is the prologue."
    return

label start:
    call play
    "This still gets run."
    return
Last edited by aegis-of-justice on Sun Mar 09, 2014 9:20 pm, edited 1 time in total.

apricotorange
Veteran
Posts: 479
Joined: Tue Jun 05, 2012 2:01 am
Contact:

Re: For loop exiting prematurely

#2 Post by apricotorange »

"renpy.call()" is a bit tricky to use: the way control flow functions work in Ren'Py is that they throw exceptions which are caught by the runtime. So everything in a Python block after the first call to "renpy.call()" never runs.

Control flow using Ren'Py statements is a bit more awkward (there isn't any for loop), but something like the following works:

Code: Select all

label start:
    $ i = 0
    while i < len(chapters):
        call expression chapters[i][1]
        "Hello world."
        $ i = i + 1
    return

User avatar
aegis-of-justice
Newbie
Posts: 9
Joined: Sun Sep 15, 2013 12:47 pm
Location: First in the the online user list!
Contact:

Re: For loop exiting prematurely

#3 Post by aegis-of-justice »

Aw man, that clears up a lot of things, haha. Thanks a lot!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot]