"return" command in script- does not return to main menu

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
mjshi
Regular
Posts: 179
Joined: Wed Mar 13, 2013 9:55 pm
Completed: MazeSite01, Ponderings of Time
Contact:

"return" command in script- does not return to main menu

#1 Post by mjshi » Sun Mar 24, 2013 10:03 pm

Code: Select all

label start:
    "Character" "Hello."
    label repeat:
        "Character" "You can go {a= next}here{/a} or {a= final}here{/a}"
        jump repeat
label next:
    "Character" "Message text"
    jump final
label final:
    "Character" "Message text"
    return
The jump repeat is so that players won't just skip over it and miss the hyperlinks.
But for some reason, the return command no longer returns to the main menu, but to the label repeat.
This is very frustrating because if I wanted to end the game, it wouldn't be possible.
How do I fix this? A ren'py full restart command sometimes gives me an error about 10 renderers or something not closing properly. I would like to use the return command, so please help! All suggestions and advice are appreciated.

User avatar
Kokoro Hane
Eileen-Class Veteran
Posts: 1219
Joined: Thu Oct 27, 2011 6:51 pm
Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, An Encounter ~In The Rain~, A Piece of Sweetness, Since When Did I Have a Combat Butler?!, Piece by Piece, +many more
Projects: Fateful Encounter, Operation: Magic Hero
Organization: Tofu Sheets Visual
Deviantart: kokoro-hane
itch: tofu-sheets-visual
Contact:

Re: "return" command in script- does not return to main menu

#2 Post by Kokoro Hane » Sun Mar 24, 2013 11:56 pm

Hmm, is your "label repeat" statement suppose to be indented that far?
PROJECTS:
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]

But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"

Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

Re: "return" command in script- does not return to main menu

#3 Post by Ryue » Mon Mar 25, 2013 7:41 am

Not 100% sure but can it be that "{a= final}here{/a}" acts like a call statement instead of as you have intended as a jump statement?
That would explain why return leads you back to 1 line after the call (which is the jump repeat).

If that is the case you should work with a variable then and use that as a check if jump repeat should be done or not.

User avatar
DragoonHP
Miko-Class Veteran
Posts: 758
Joined: Tue Jun 22, 2010 12:54 am
Completed: Christmas
IRC Nick: DragoonHP
Location: Zion Island, Solario
Contact:

Re: "return" command in script- does not return to main menu

#4 Post by DragoonHP » Mon Mar 25, 2013 7:54 am

Hyperlinks are called in a new context and so that means when the game encounters the return statement, it jumps back to the old label.

You will be better off using the menu statement for branching, but if you're really fixed on using the hyperlinks, modify the default hyperlink function by using config.hyperlink_callback

User avatar
mjshi
Regular
Posts: 179
Joined: Wed Mar 13, 2013 9:55 pm
Completed: MazeSite01, Ponderings of Time
Contact:

Re: "return" command in script- does not return to main menu

#5 Post by mjshi » Mon Mar 25, 2013 10:03 am

@ Kokoro Hane: I was doubtful if it worked at first, but when I ran the game as a test trial the text under the "label repeat" showed up perfectly fine.

@ Wolf: Hmm, I'll try using {a= jump repeat}/{a=jump repeat} instead of {a=repeat} and see if that works. Maybe just using {a= repeat} called up the label repeat instead of jumping to it.

@ DragoonHP: Well, yeah, but the game uses both NVL mode and regular dialogue so I'm not sure how to get the choices menu show up on the NVL screen without messing up my regular dialogue choices. Is that possible?

EDIT:
@ Wolf, {a= jump repeat} did not work.

User avatar
arachni42
Veteran
Posts: 341
Joined: Mon Feb 25, 2013 6:33 pm
Organization: no, I'm pretty messy
Location: New York
Contact:

Re: "return" command in script- does not return to main menu

#6 Post by arachni42 » Tue Mar 26, 2013 2:07 am

Maybe I can explain what I think is happening here. The problem is that "return" isn't a command, but a special statement in programming. In memory, computers keep commands in a stack -- it works just like a stack of plates. If you have something like:

Code: Select all

MyPseudoCode:
    main menu:
        play start animation
        call MyAwesomeFunction
        play ending animation
So "main menu" will go on the stack, then it will "play start animation," and then MyAwesomeFunction will go on the stack. When MyAwesomeFunction is done running, the "return" statement at the end tells it to take MyAwesomeFunction off of the top of the stack and continue from where it left off (which is inside "main menu," right after "call MyAwesomeFunction"). At that point, it goes on to run "play ending animation."

So, line-by-line, this is what's happening in your code:

You go into the block labelled start, so the stack looks like this:
2. start block
1. main menu

Then the character says "Hello."
3. the end of the line of "Character" "Hello."
2. start block
1. main menu

Then you enter a new block, labelled repeat:
4. repeat block
3. the end of the line of "Character" "Hello."
2. start block
1. main menu

It runs the line with the links:
5. end of the line of "Character" "You can go {a= next}here{/a} or {a= final}here{/a}"
4. repeat block
3. the end of the line of "Character" "Hello."
2. start block
1. main menu

The player clicks final, so it jumps to final:
6. final block
5. end of the line of "Character" "You can go {a= next}here{/a} or {a= final}here{/a}"
4. repeat block
3. the end of the line of "Character" "Hello."
2. start block
1. main menu

Now it executes the line "Character" "Message text." Then it hits RETURN. Return tells it to take the top off the stack (because it's done with it). So right after the happens, the stack is:
5. end of the line of "Character" "You can go {a= next}here{/a} or {a= final}here{/a}"
4. repeat block
3. the end of the line of "Character" "Hello."
2. start block
1. main menu

The next line is "jump repeat." So it repeats. If the repeat were not there, it would finish the repeat block. There aren't any more commands in the repeat block, so by default, that would come off the stack and it would go back to the end of the Hello line. There's nothing after that, so that would come off the stack and it would go back to the start block, and there's nothing else in that start block, so it would go back to the main menu.

Return isn't unlike the Back button on a browser -- it goes back to where it came from; it's difficult to see in this case because of the nested labels. It's used in programming because you can (but don't have to) pass values with it.

I hope this explanation wasn't too technical. :) Hopefully it'll help you understand the behavior so you can rearrange things to work as you want them to.
I, Miku (NaNoRenO 2014)
Vignettes (NaNoRenO 2013)
_________________

User avatar
mjshi
Regular
Posts: 179
Joined: Wed Mar 13, 2013 9:55 pm
Completed: MazeSite01, Ponderings of Time
Contact:

Re: "return" command in script- does not return to main menu

#7 Post by mjshi » Wed Mar 27, 2013 9:54 pm

@ arachni42: Hmm... the explanation with the "stacks" and the "back button" made a lot of sense (to me, anyway). So I guess instead of using hyperlinks and "jump repeat" which puts us in an infinite loop, I should instead use the NVL mode menu (the only reason for hyperlinks is because I didn't know how to get the NVL menu to work without disrupting my ADV mode menus- I still don't know how). I guess I'll have to figure it out, then...
Unless you could help me with that too? ^.^'
(just click the linked "I still don't know how")

User avatar
arachni42
Veteran
Posts: 341
Joined: Mon Feb 25, 2013 6:33 pm
Organization: no, I'm pretty messy
Location: New York
Contact:

Re: "return" command in script- does not return to main menu

#8 Post by arachni42 » Thu Mar 28, 2013 9:12 pm

mjshi wrote:I should instead use the NVL mode menu (the only reason for hyperlinks is because I didn't know how to get the NVL menu to work without disrupting my ADV mode menus- I still don't know how).
Ah ha, well, that is easier than arranging a workaround for the hyperlinks if that's what you're trying to accomplish. I have posted an answer in the other thread.
I, Miku (NaNoRenO 2014)
Vignettes (NaNoRenO 2013)
_________________

Post Reply

Who is online

Users browsing this forum: No registered users