Solved: Return isn't sending player 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
AliceGames
Newbie
Posts: 13
Joined: Fri Jul 23, 2021 10:06 am
Contact:

Solved: Return isn't sending player to main menu

#1 Post by AliceGames »

Hello! I have a death scene in my game, at the bottom of the script, but when I have a screen jump to the label, it plays the scene but then returns back to where the player was prior to dying.
Any reason for this?

Code: Select all

screen bloodlevels:
    imagebutton:
        idle "return button Idle.png"
        hover "return button Hover.png"
        focus_mask True
        action Return()
        hovered [ Play ("sound", "soundeffects/click.mp3") ]
    text "Blood Left: [currenthp]/[maxhp]" xalign 0.0 yalign 0.05
    bar value currenthp range maxhp xalign 0.0 yalign 0.1 xmaximum 200
    timer 1.0 repeat True:
        if currenthp > 0:
            action SetVariable('currenthp', currenthp - 20)
        else:
            action Jump("death")
Thats my screen, and here is the (temporary) death scene.

Code: Select all

label death:
    "I am dead"
    return
Last edited by AliceGames on Mon Jul 26, 2021 10:04 pm, edited 1 time in total.

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

Re: Return isn't sending player to main menu

#2 Post by Ocelot »

return returns to the place at the top of so-called call stack or to main menu if call stack is empty. Each time you call a label, you place line where you call from on top of the call stack. Any return will return to that place. For example:

Code: Select all

label death:
    "I am dead"
    return

label start:
    "..."
    # if you die here, you will return to the main menu
    call some_scene
   "I survived"
    return

label some_scene:
    "..."
    # if you die here, you will return to the place this label was called from
    return 
If you want unconditional return to the main menu, use $ renpy.full_restart() instead.
< < insert Rick Cook quote here > >

AliceGames
Newbie
Posts: 13
Joined: Fri Jul 23, 2021 10:06 am
Contact:

Re: Return isn't sending player to main menu

#3 Post by AliceGames »

Ocelot wrote: Mon Jul 26, 2021 6:54 pm return returns to the place at the top of so-called call stack or to main menu if call stack is empty. Each time you call a label, you place line where you call from on top of the call stack. Any return will return to that place. For example:

Code: Select all

label death:
    "I am dead"
    return

label start:
    "..."
    # if you die here, you will return to the main menu
    call some_scene
   "I survived"
    return

label some_scene:
    "..."
    # if you die here, you will return to the place this label was called from
    return 
If you want unconditional return to the main menu, use $ renpy.full_restart() instead.
Ok, thank you, I’ll try this! Can I ask though, does it matter where you place the death label? Does it need to be at the end of the script?

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

Re: Return isn't sending player to main menu

#4 Post by Ocelot »

No, label placement only matters if you "fall through" it without returning or jumping: in this case next label will be run:

Code: Select all

label death:
    "I am dead"
    $ renpy.full_restart() 
    # does not matter where it is, because control will not leave it anyway

label start:
    "start"
    # relative positioning of start and scene01 labels is important
    # because we want scene01 play right after the start scene

label scene01:
    "scene 1"
    jump death
   # what after scene01 does not matter because we are explicitely jumping to the next label.
< < insert Rick Cook quote here > >

AliceGames
Newbie
Posts: 13
Joined: Fri Jul 23, 2021 10:06 am
Contact:

Re: Return isn't sending player to main menu

#5 Post by AliceGames »

Ocelot wrote: Mon Jul 26, 2021 7:14 pm No, label placement only matters if you "fall through" it without returning or jumping: in this case next label will be run:

Code: Select all

label death:
    "I am dead"
    $ renpy.full_restart() 
    # does not matter where it is, because control will not leave it anyway

label start:
    "start"
    # relative positioning of start and scene01 labels is important
    # because we want scene01 play right after the start scene

label scene01:
    "scene 1"
    jump death
   # what after scene01 does not matter because we are explicitely jumping to the next label.
Oh, ok, thank you!!

Post Reply

Who is online

Users browsing this forum: Google [Bot]