[Solved] Problems with the Return function

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
darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

[Solved] Problems with the Return function

#1 Post by darckshame »

Hello guys, I want to make a cheat menu for a game that has all it's content in 4 labels that represent 4 days of the game and it's a linear action with no labels to jump to, only reed, chose, add or remove variables depending on your choice, continue reading.... so I made this:

Code: Select all

    
    ####################
    ##Cheat game name##
    ####################
  

init python:
    config.overlay_screens.append( "cheat" )
    
image mod_cheat_menu_background = "138"

screen cheat:
    order_reverse True
    key "1" action Jump("nfo")
    textbutton "{color=#1DDB16}{b}Cheat Menu{/b]{/color}":
        xalign 0.01
        action Jump("nfo")
        background "#006"
        insensitive_background "#444"
        hover_background "#00a"

label nfo:
    scene mod_cheat_menu_background
    python:
        try: 
            infoScreenSeen
        except:
            infoScreenSeen = False
    jump mod_show_info




label mod_show_info:
    if infoScreenSeen:
        jump mod_cheat_menu

    scene mod_cheat_menu_background
    "This cheat menu is not part of the original game."
    "If the {color=#1DDB16}{b}Cheat Menu{/b]{/color} {color=#FFBB00}doesn't appear in some screens just press the place were it should have been or press key{/color} {color=#1DDB16}{b}'1'{/b]{/color}"
    "Everything should work fine, but I highly recommend you save your game before using it."
    $ infoScreenSeen = True
    menu:
        "go back to your game":
            return
        "continue without saving":
            jump mod_cheat_menu

label mod_cheat_menu:
    scene mod_cheat_menu_background
    
    menu:
        "Money cheat":
            jump mod_cheat_money
        "Romance points(RP)":
            jump mod_cheat_characters
        "I want a new name!":
            $ player_name = ""
            $ player_name = renpy.input("Type your name (or just hit Enter for John as a default name.")
            $ player_name = player_name.strip()
            if player_name == "":
                $ player_name = "John"
            
            $ renpy.retain_after_load()
            $ renpy.restart_interaction()
            
            "Your name now is {color=#1DDB16}{b}[player_name]{/b}{/color}"
            jump mod_cheat_menu
        "Close cheat menu":
            return
            
label mod_cheat_money:
    scene mod_cheat_menu_background

    menu:
        "Give me $10000!":
            $ money += 10000
             
            $ renpy.retain_after_load()
            $ renpy.restart_interaction()
            jump mod_cheat_money
        "What amount of money do you want?":
            $ money += int(renpy.input("How much money to add?", allow="0123456789") or 0)
            
            $ renpy.retain_after_load()
            $ renpy.restart_interaction()
            jump mod_cheat_money
        "Back":
            jump mod_cheat_menu
            
label mod_cheat_characters:
    scene mod_cheat_menu_background      
    
    menu:
        "xxx (RP: [RPx])":
            menu:
                "Add":
                    $ RPx += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
                "Remove":
                    $ RPx -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
        "zzz (RP: [RPz])":
            menu:
                "Add":
                    $ RPz += int(renpy.input("How much to add?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
                "Remove":
                    $ RPz -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    jump mod_cheat_characters
        "yyy (RP: [RPy])":
            menu:
                "Add":
                    $ RPy += int(renpy.input("How much to add?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
                "Remove":
                    $ RPy -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
        "www (RP: [RPw])":
            menu:
                "Add":
                    $ RPw += int(renpy.input("How much to add?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
                "Remove":
                    $ RPw -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
        "vvv (RP: [RPv])":
            menu:
                "Add":
                    $ RPv += int(renpy.input("How much to add?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
                "Remove":
                    $ RPv -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                     
                    $ renpy.retain_after_load()
                    $ renpy.restart_interaction()
                    jump mod_cheat_characters
        "Back":
            jump mod_cheat_menu
But the return function returns me to the games main menu I even tried to use

Code: Select all

 $ renpy.retain_after_load()
 $ renpy.restart_interaction()
so that it'll retain the changes - this was added after the return function didn't work and I read some post, so yah...

What I want to do is make the mod do something like when you enter save or load menu so that when it closes you go back to the screen you were watching

I know that maybe what I did it's not the best way to do it and that I'm a newb at it but can you please help me?
Last edited by darckshame on Sat Mar 17, 2018 10:03 pm, edited 1 time in total.

User avatar
Lord Hisu
Regular
Posts: 58
Joined: Sun Feb 11, 2018 2:31 am
Contact:

Re: Problems with the Return function

#2 Post by Lord Hisu »

Instead of jumping to a label, you could use call. That way, when you return, you will be back to where you called the label.

Code: Select all

label start:
    "1"
    call next_label # Try changing this to jump and see what happens
    "2"
    
label next_label:
    "3"

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#3 Post by darckshame »

I have used call instead of jump but it always returns me to the mod_cheat_menu

I even used:

Code: Select all

            python:
                renpy.return_statement()
same thing

Code: Select all

    
    ####################
    ##Cheat game name##
    ####################

init python:
    config.overlay_screens.append( "cheat" )
    
image mod_cheat_menu_background = "138"

screen cheat:
    order_reverse True
    key "1" action Function(renpy.call, label="nfo")   ##Jump("nfo")
    textbutton "{color=#1DDB16}{b}Cheat Menu{/b]{/color}":
        xalign 0.01
        action Function(renpy.call, label="nfo")   ##Jump("nfo")
        background "#006"
        insensitive_background "#444"
        hover_background "#00a"

label nfo:
    scene mod_cheat_menu_background
    python:
        try: 
            infoScreenSeen
        except:
            infoScreenSeen = False
    call mod_show_info




label mod_show_info:
    if infoScreenSeen:
        call mod_cheat_menu

    scene mod_cheat_menu_background
    "This cheat menu is not part of the original game."
    "If the {color=#1DDB16}{b}Cheat Menu{/b]{/color} {color=#FFBB00}doesn't appear in some screens just press the place were it should have been or press key{/color} {color=#1DDB16}{b}'1'{/b]{/color}"
    "Everything should work fine, but I highly recommend you save your game before using it."
    $ infoScreenSeen = True
    menu:
        "go back to the game":
            ##return
            python:
                renpy.return_statement()
        "continue without saving":
            call mod_cheat_menu

label mod_cheat_menu:
    show 138

    menu:
        "Money cheat":
            call mod_cheat_money
        "Romance points":
            call mod_cheat_characters
        "I want a new name!":
            $ player_name = ""
            $ player_name = renpy.input("Type your name (or just hit Enter for Tom as a default name.")
            $ player_name = player_name.strip()
            if player_name == "":
                $ player_name = "Tom"
        "Close cheat menu":
            ##return
            python:
                renpy.return_statement()
            
label mod_cheat_money:
    scene mod_cheat_menu_background

    menu:
        "Give me $10000!":
            $ money += 10000
            call mod_cheat_money
        "What amount of money do you want?":
            $ money += int(renpy.input("How much money to add?", allow="0123456789") or 0)
            call mod_cheat_money
        "Back":
            call mod_cheat_menu
            
label mod_cheat_characters:
    scene mod_cheat_menu_background      
    
    menu:
        "xxx (RP: [RPx])":
            menu:
                "Add":
                    $ RPx += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPx -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "zzz (RP: [RPz])":
            menu:
                "Add":
                    $ RPz += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPz -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "yyy (RP: [RPy])":
            menu:
                "Add":
                    $ RPy += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPy -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "www (RP: [RPw])":
            menu:
                "Add":
                    $ RPw += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPw -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "vvv (RP: [RPv])":
            menu:
                "Add":
                    $ RPv += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPv -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "Back":
            call mod_cheat_menu
 

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#4 Post by darckshame »

The strange thing is when i try to close the cheat menu it goes to mod_show_info then i go to mod_cheat_menu and try again to exit it and this time it works, anyone know why or a work around?

User avatar
Milkymalk
Miko-Class Veteran
Posts: 753
Joined: Wed Nov 23, 2011 5:30 pm
Completed: Don't Look (AGS game)
Projects: KANPEKI! ★Perfect Play★
Organization: Crappy White Wings
Location: Germany
Contact:

Re: Problems with the Return function

#5 Post by Milkymalk »

In the label "nfo", you call the label "mod_show_info". When you return from there, you jump back to exactly where you came from. After that call line, there's nothing else, so the script continues and you are back in "mod_show_info".
You just need a "return" at the end of the "nfo" block.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#6 Post by darckshame »

Milkymalk that helped with the exiting to the game from the "mod_show_info" but when you try to exit the mod from "mod_cheat_menu" I'm sent back to the "mod_show_info" then if I'm entering the label "mod_cheat_menu" and try to exit again now it does what it's supposed to do. I even tried to add an return at the end of "mod_show_info"

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Problems with the Return function

#7 Post by Alex »

When you call a label you need to add a return statement at the end of this label to return back to the place where it was called.
In your script you call a label, then in this label you call another label, and in that label you call another label... so all the labels you want to call need a return statement to let you return to your normal game flow. Like

Code: Select all

label start:
    "..."
    call lbl1
    "the end"
    return # to end the game and not go to other labels

label lbl1:
    "1"
    call lbl2
    "?"
    return # will return to start

label lbl2:
    "2"
    "... ..."
    return # will return to lbl1

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#8 Post by darckshame »

Alex I had no luck, the same thing happens

Code: Select all

    
    ####################
    ##Cheat game name##
    ####################

##image mod_cheat_menu_background = "138.jpg"


init python:
    config.overlay_screens.append( "cheat" )

screen cheat:
    order_reverse True
    key "1" action Function(renpy.call, label="nfo")  ##Jump("nfo")
    textbutton "{color=#1DDB16}{b}Cheat Menu{/b]{/color}":
        xalign 0.01
        action Function(renpy.call, label="nfo")  ##Jump("nfo")
        background "#006"
        insensitive_background "#444"
        hover_background "#00a"

    
label nfo:
    ##scene mod_cheat_menu_background
    python:
        try: 
            infoScreenSeen
        except:
            infoScreenSeen = False
    call mod_show_info
    return




label mod_show_info:
    if infoScreenSeen:
        call mod_cheat_menu

    
    ##scene mod_cheat_menu_background
    "{color=#FFBB00}This cheat menu is not part of the original game.{/color}"
    "{color=#FFBB00}If the {/color}{color=#1DDB16}{b}Cheat Menu{/b]{/color} {color=#FFBB00}doesn't appear in some screens just press the place were it should have been or press key{/color} {color=#1DDB16}{b}'1'{/b]{/color}"
    "{color=#FFBB00}Everything should work fine, but I highly recommend you save your game before using it.{/color}"
    $ infoScreenSeen = True
    menu:
        "go back to your game":
            python:
                renpy.return_statement()
        "continue without saving":
            call mod_cheat_menu
    return

label mod_cheat_menu:
    ##scene mod_cheat_menu_background
    $ renpy.retain_after_load()
    $ renpy.restart_interaction()

    menu:
        "Money cheat":
            call mod_cheat_money
        "Romance points":
            call mod_cheat_characters
        "I want a new name!":
            $ player_name = renpy.input("Type your new name (or just hit Enter for Tom as a default name).")
            $ player_name = player_name.strip()

            if player_name:
                "Name set to [player_name]"
            else:
                $ player_name = "Tom"
                "Name set to default name: [player_name]"
            jump mod_cheat_menu
            ##$ player_name = ""
            ##$ player_name = renpy.input("Type your name (or just hit Enter for Tom as a default name.")
            ##$ player_name = player_name.strip()
            ##if player_name == "":
                ##$ player_name = "Tom"
        "Close cheat menu":
            python:
                renpy.return_statement()    ### event tried return just by itself
    return
                
            
label mod_cheat_money:
    ##scene mod_cheat_menu_background

    menu:
        "Give me $10000!":
            $ money += 10000
            call mod_cheat_money
        "What amount of money do you want?":
            $ money += int(renpy.input("How much money to add?", allow="0123456789") or 0)
            call mod_cheat_money
        "Back":
            call mod_cheat_menu
    return
            
label mod_cheat_characters:
    ##scene mod_cheat_menu_background      
    
    menu:
        "xxx (RP: [RPx])":
            menu:
                "Add":
                    $ RPx += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPx -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "zzz (RP: [RPz])":
            menu:
                "Add":
                    $ RPz += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPz -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "yyy (RP: [RPy])":
            menu:
                "Add":
                    $ RPy += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPy -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "www (RP: [RPw])":
            menu:
                "Add":
                    $ RPw += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPw -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "vvv (RP: [RPv])":
            menu:
                "Add":
                    $ RPv += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPv -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "Back":
            call mod_cheat_menu
    return

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Problems with the Return function

#9 Post by Alex »

So how does the start label look like?
Why do you add your screen to overlay - just show it at the vary beginning of the game?
Why not to use call action - https://www.renpy.org/doc/html/screen_actions.html instead of function action?

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#10 Post by darckshame »

Alex I can't use the call action there because this what I get so that's why I use the function because it's the only way to call something in that context

Code: Select all

line 16, in keywords key "1" action Call("nfo")  ##Function(renpy.call, label="nfo")  ##Jump("nfo")
NameError: name 'Call' is not defined


Call

The equivalent of the call statement is the renpy.call function.

Code: Select all

renpy.call(label, *args, **kwargs)
Causes the current Ren'Py statement to terminate, and a jump to a label to occur. When the jump returns, control will be passed to the statement following the current statement.

from_current
If true, control will return to the current statement, rather than the statement following the current statement. (This will lead to the current statement being run twice. This must be passed as a keyword argument.)

Code: Select all

renpy.return_statement()
Causes Ren'Py to return from the current Ren'Py-level call.

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#11 Post by darckshame »

So far this is how I made it work. So I removed from the equation the label nfo and I think I've solved the problem.

Code: Select all

##image mod_cheat_menu_background = "138.jpg"

init:
    $ infoScreenSeen = False

init python:
    config.overlay_screens.append( "cheat" )

screen cheat:
    order_reverse True
    key "1" action Function(renpy.call, label="mod_show_info")  ##Jump("nfo")
    textbutton "{color=#1DDB16}{b}Cheat Menu{/b]{/color}":
        xalign 0.01
        action Function(renpy.call, label="mod_show_info")  ##Jump("nfo")
        background "#006"
        insensitive_background "#444"
        hover_background "#00a"
    
    
##label nfo:
    ##scene mod_cheat_menu_background
    ##python:
        ##try: 
            ##infoScreenSeen
        ##except:
            ##infoScreenSeen = False
    ##call mod_show_info
    ##return




label mod_show_info:
    ##if infoScreenSeen:
        ##call mod_cheat_menu

    
    ##scene mod_cheat_menu_background
    if infoScreenSeen == True:
        call mod_cheat_menu
    else:
        "{color=#FFBB00}This cheat menu is not part of the original game.{/color}"
        "{color=#FFBB00}If the {/color}{color=#1DDB16}{b}Cheat Menu{/b]{/color} {color=#FFBB00}doesn't appear in some screens just press the place were it should have been or press key{/color} {color=#1DDB16}{b}'1'{/b]{/color}"
        "{color=#FFBB00}Everything should work fine, but I highly recommend you save your game before using it.{/color}"
        $ infoScreenSeen = True
        menu:
            "go back to your game":
                python:
                    renpy.return_statement()
            "continue without saving":
                call mod_cheat_menu
    return

label mod_cheat_menu:
    ##scene mod_cheat_menu_background
    ##$ renpy.retain_after_load()
    ##$ renpy.restart_interaction()

    menu:
        "Money cheat":
            call mod_cheat_money
        "Romance points":
            call mod_cheat_characters
        "I want a new name!":
            $ player_name = renpy.input("Type your new name (or just hit Enter for Tom as a default name).")
            $ player_name = player_name.strip()

            if player_name:
                "Name set to [player_name]"
            else:
                $ player_name = "Tom"
                "Name set to default name: [player_name]"
            call mod_cheat_menu
            ##$ player_name = ""
            ##$ player_name = renpy.input("Type your name (or just hit Enter for Tom as a default name.")
            ##$ player_name = player_name.strip()
            ##if player_name == "":
                ##$ player_name = "Tom"
        "Close cheat menu":
            return()
    return
                
            
label mod_cheat_money:
    ##scene mod_cheat_menu_background

    menu:
        "Give me $10000!":
            $ money += 10000
            call mod_cheat_money
        "What amount of money do you want?":
            $ money += int(renpy.input("How much money to add?", allow="0123456789") or 0)
            call mod_cheat_money
        "Back":
            call mod_cheat_menu
    return
            
label mod_cheat_characters:
    ##scene mod_cheat_menu_background      
    
    menu:
        "xxx (RP: [RPx])":
            menu:
                "Add":
                    $ RPx += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPx -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "zzz (RP: [RPz])":
            menu:
                "Add":
                    $ RPz += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPz -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "yyy (RP: [RPy])":
            menu:
                "Add":
                    $ RPy += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPy -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "www (RP: [RPw])":
            menu:
                "Add":
                    $ RPw += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPw -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "vvv (RP: [RPv])":
            menu:
                "Add":
                    $ RPv += int(renpy.input("How much to add?", allow="0123456789") or 0)
                    call mod_cheat_characters
                "Remove":
                    $ RPv -= int(renpy.input("How much to remove?", allow="0123456789") or 0)
                    call mod_cheat_characters
        "Back":
            call mod_cheat_menu
    return

darckshame
Newbie
Posts: 23
Joined: Sun Feb 25, 2018 11:39 pm
Contact:

Re: Problems with the Return function

#12 Post by darckshame »

For now it's solved

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot], Ocelot