Accessing Return() values

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
Milkymalk
Miko-Class Veteran
Posts: 742
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:

Accessing Return() values

#1 Post by Milkymalk » Thu Nov 24, 2011 12:39 pm

From the documentation:
Return(value=None)

Causes the current interaction to return the supplied value. This is often used with menus and imagemaps, to select what the return value of the interaction is.

When in a menu, this returns from the menu.
How do I actually access the returned value after I get it from a called screen?

User avatar
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Accessing Return() values

#2 Post by herenvardo » Thu Nov 24, 2011 12:49 pm

The value gets stored in the _return global variable. Just make sure to retrieve it before anything else "returns" something and replaces the value.

For example:

Code: Select all

call screen myScreen
$ myScreenReturnedValue = _return # now the value is safe
# Do more stuff ...
# And later use myScreenReturnedValue for whatever you need
If you are going to use the value immediately after the call returns, you probably won't need to save it into a variable.
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
Milkymalk
Miko-Class Veteran
Posts: 742
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: Accessing Return() values

#3 Post by Milkymalk » Thu Nov 24, 2011 1:05 pm

Thank you :D It's little bits of information like that that I miss in a lot of places.
Crappy White Wings (currently quite inactive)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)

User avatar
Abeiramar
Regular
Posts: 198
Joined: Wed Jul 28, 2010 10:37 am
Location: Portugal
Contact:

Re: Accessing Return() values

#4 Post by Abeiramar » Sat Nov 26, 2011 1:05 pm

I would like to ask something about the Return() thingy...

When I'm on a screen and I create this button:

Code: Select all


screen blah:

    textbutton _("Return") action Return()

It brings me back to the main game menu instead of the label where I was at :? ! Why is that?

User avatar
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Accessing Return() values

#5 Post by herenvardo » Sat Nov 26, 2011 2:23 pm

Abeiramar wrote:I would like to ask something about the Return() thingy...

When I'm on a screen and I create this button:

Code: Select all


screen blah:

    textbutton _("Return") action Return()

It brings me back to the main game menu instead of the label where I was at :? ! Why is that?
Let me guess, did you use "show screen" instead of "call screen"?

A call (be it for a label, a screen, or a python function) does two things:
First, and best known, it "jumps" to the label, screen, or function being called. But it also places the current location in the script (this is, the point from which the call is being made) in the top of a structure known as the "return stack".
When something "returns", the engine "pops" whatever is at the top of the return stack (ie: retrieves the value, and removes it from the stack), and jumps to that point.

Furthermore, when you select "Start Game" on the main menu (or anything equivalent if your menu is customized), the engine simply calls the "start" label. In other words, it places the main menu at the top of the return stack and jumps to the label. Unless you "call" something in between, the next time something "return"s it will return to that point (the main menu).

In summary: if you are using "call screen", Return() should work fine for that screen. If you are using "show screen", you shouldn't use Return(), you have "hide screen" instead (or its python equivalent renpy.hide_screen())

HTH
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
Abeiramar
Regular
Posts: 198
Joined: Wed Jul 28, 2010 10:37 am
Location: Portugal
Contact:

Re: Accessing Return() values

#6 Post by Abeiramar » Sat Nov 26, 2011 4:39 pm

Interesting! However, it doesn't seem to work :( ...

Code: Select all

label odd_man:
    
    "Would you like to see my photos?"
    
    menu:

        "Yes, I would like to see some pretty pictures":
             jump pics

            
        "Leave me alone":
             jump im_free


label pics:
    
    call screen pictures
    
screen pictures:
    
    add "awesome_picture.jpg" xalign 0.0 yalign 0.0
    add "awesome_picture2.jpg" xalign 200 yalign 0.0
    
    text "LOOK AT THOSE AWESOME PHOTOS" size 38 color("#ffffff") xpos 130 ypos 20
    
    textbutton _("Return") action Return() xpos 58 ypos 500 #Brings me back to the Main Game Menu again >_> 

Sadly, the Return() brings me to the Main Game Menu instead of the menu of label odd_man !
Are you sure it's just "call screen" ?

Thank you very much for answering anyway :D !

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

Re: Accessing Return() values

#7 Post by DragoonHP » Sat Nov 26, 2011 4:46 pm

There is nothing wrong with the code... but you are being redirected to main menu because your labels pics contains just a single block... that is by which you call the screen...

So when the interaction with the screen completes(or in this case, use return function), the control is given back to the label pics, which passes it to main menu because it has already processed all of it's block...

Let me know if you were able to understand it at all...

User avatar
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Accessing Return() values

#8 Post by herenvardo » Sat Nov 26, 2011 5:04 pm

Rewording what DragoonHP already said:

Your return is not really bringing you to the Main Game Menu: it brings you to just after the "call screen" statement, and the game goes on from there... Only that there is nothing after the call screen, so the script has "ended" and the engine brings you back to the menu.

To do a quick test, add some simple statement after the call. A character-less say like this may do:

Code: Select all

    call screen pictures
    "Now we have returned from the screen"
Now, after returning from the screen, you should be seeing that line of text, as said by the "narrator" (the implicit character object for lines without an actual character). And, after that line, you'll get back to the menu, but it will at least confirm that things are going on properly.

Beyond that little test to see that nothing weird is going on, you need to ask yourself: what do you want the game to do after returning from that screen? If you want to go to some label, put a "jump" statement after the call; if you want to show a menu, put a "menu" statement; if you want to show some dialogue then put in the "say" statements, and so on.

In summary: the Retrun() brings you back to the right place (just after the call), but the game goes back to the main menu because there is nothing else to do.

HTH
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

User avatar
Abeiramar
Regular
Posts: 198
Joined: Wed Jul 28, 2010 10:37 am
Location: Portugal
Contact:

Re: Accessing Return() values

#9 Post by Abeiramar » Sat Nov 26, 2011 5:16 pm

Thanks for the answers :D . I solved the problem and I also understand the Return() function better. Yes, it works the just the way you're saying Herenvardo.

I followed your advice and put

Code: Select all

    textbutton _("Return") action Jump("odd_man") xpos 58 ypos 500
instead.

It works the way I want now~

User avatar
herenvardo
Veteran
Posts: 359
Joined: Sat Feb 25, 2006 11:09 am
Location: Sant Cugat del Vallès (Barcelona, Spain)
Contact:

Re: Accessing Return() values

#10 Post by herenvardo » Sat Nov 26, 2011 5:54 pm

So you are not "returning" anymore, but just jumping to the "odd_man" label.
That's fine, as long as that's what you want, but let me share an alternative approach:

You could leave your button as it was:

Code: Select all

    textbutton _("Return") action Return() xpos 58 ypos 500
but then add the jump after calling (and returning from) the screen:

Code: Select all

    call screen pictures
    jump odd_man
If you are calling the screen from a single point in your scripts, then there is no difference at all between one form or the other.

However, if you want to reuse the screen (calling it from different parts of your code), there is a difference:
Your method (jumping from the screen itself) will cause each call to jump to the "odd_man" label upon clicking the button.
The "Return() + jump" method allows to do something different from each point in the script where the screen is called.

Use the approach that best fits your needs ;)
I have failed to meet my deadlines so many times I'm not announcing my projects anymore. Whatever I'm working on, it'll be released when it is ready :P

Post Reply

Who is online

Users browsing this forum: Google [Bot]