[SOLVED] How to return to the start of a block?

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
Greeny
Miko-Class Veteran
Posts: 921
Joined: Sun Dec 20, 2009 10:15 am
Completed: The Loop, The Madness
Projects: In Orbit, TBA
Organization: Gliese Productions
Location: Cantankerous Castle
Contact:

[SOLVED] How to return to the start of a block?

#1 Post by Greeny »

The question here is, can I return to the start of a particular block without the use of labels?
That means, without using jump or call. That would seriously mess up my vibe, y'know.

What I have is this:

Code: Select all

block:
    if cheeze.minutes < 60:
        "It's not cheeze o'clock yet."
        menu:
            "Check the clock":
                if cheeze.minutes > 55:
                    "But it will be soon."
                    menu:
                         "Go for the cheeze":
                              $ cheeze.minutes = 60
                              # Here I need it to go to the start again, to check for the cheeze time, which should now return the "else" option.
                              # Unless there's a way to jump to the "else" option from here?
                         "Play badminton":
                              # There's only text here, so this option leads to the badminton.
                else:
                    "I think I'll go have a cup of coffee."
                    jump coffee
            "Go play badminton":
                # Here it goes to badminton normally, even without any jumps or calls.
    else:
        "Wait, I don't even like cheeze."
        jump onoes

# There's badminton going on here.
I hope this example makes it clear what I need to achieve.
Last edited by Greeny on Thu Aug 05, 2010 12:43 am, edited 1 time in total.
In Orbit [WIP] | Gliese is now doing weekly erratic VN reviews! The latest: Halloween Otome!
Gliese Productions | Facebook | Twitter
Image

Incendium
Regular
Posts: 25
Joined: Wed Dec 09, 2009 12:57 am
Contact:

Re: How to return to the start of a block?

#2 Post by Incendium »

It is certainly possible, but it requires use of a while statement, a control variable and careful attention to detail to make sure you don't get stuck in an infinite loop. Here is a simple example:

Code: Select all

label start:
    $ looping = True

    while looping:
        'Ohnoes, we\'re stuck in an infinite loop!'
        menu:
            'Do nothing':
                pass
            'Search for a way out':
                $ looping = False
        if looping:
            'Halp!'
    'Hooray, we got out!'
Now if we apply that to your code, we get this:

Code: Select all

$ cheeze_action = None
while not cheeze_action:
    if cheeze.minutes < 60:
        "It's not cheeze o'clock yet."
        menu:
            "Check the clock":
                if cheeze.minutes > 55:
                    "But it will be soon."
                    menu:
                         "Go for the cheeze":
                              $ cheeze.minutes = 60
                         "Play badminton":
                              $ cheeze_action = "badminton"
                else:
                    "I think I'll go have a cup of coffee."
                    jump coffee
            "Go play badminton":
                $ cheeze_action = "badminton"
    else:
        "Wait, I don't even like cheeze."
        jump onoes

# There's badminton going on here.

User avatar
Greeny
Miko-Class Veteran
Posts: 921
Joined: Sun Dec 20, 2009 10:15 am
Completed: The Loop, The Madness
Projects: In Orbit, TBA
Organization: Gliese Productions
Location: Cantankerous Castle
Contact:

Re: How to return to the start of a block?

#3 Post by Greeny »

Thanks, that's exactly what I was looking for!
In Orbit [WIP] | Gliese is now doing weekly erratic VN reviews! The latest: Halloween Otome!
Gliese Productions | Facebook | Twitter
Image

Post Reply

Who is online

Users browsing this forum: No registered users