Page 1 of 1

Accessing Return() values

Posted: Thu Nov 24, 2011 12:39 pm
by Milkymalk
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?

Re: Accessing Return() values

Posted: Thu Nov 24, 2011 12:49 pm
by herenvardo
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.

Re: Accessing Return() values

Posted: Thu Nov 24, 2011 1:05 pm
by Milkymalk
Thank you :D It's little bits of information like that that I miss in a lot of places.

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 1:05 pm
by Abeiramar
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?

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 2:23 pm
by herenvardo
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

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 4:39 pm
by Abeiramar
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 !

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 4:46 pm
by DragoonHP
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...

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 5:04 pm
by herenvardo
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

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 5:16 pm
by Abeiramar
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~

Re: Accessing Return() values

Posted: Sat Nov 26, 2011 5:54 pm
by herenvardo
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 ;)