How do I actually access the returned value after I get it from a called screen?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.
Accessing Return() values
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.
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.
- Milkymalk
- Miko-Class Veteran
- Posts: 762
- 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
From the documentation:
-
- Veteran
- Posts: 359
- Joined: Sat Feb 25, 2006 11:09 am
- Location: Sant Cugat del Vallès (Barcelona, Spain)
- Contact:
Re: Accessing Return() values
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:
If you are going to use the value immediately after the call returns, you probably won't need to save it into a variable.
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
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
- Milkymalk
- Miko-Class Veteran
- Posts: 762
- 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
Thank you 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)
Working on: KANPEKI!
(On Hold: New Eden, Imperial Sea, Pure Light)
Re: Accessing Return() values
I would like to ask something about the Return() thingy...
When I'm on a screen and I create this button:
It brings me back to the main game menu instead of the label where I was at ! Why is that?
When I'm on a screen and I create this button:
Code: Select all
screen blah:
textbutton _("Return") action Return()
-
- Veteran
- Posts: 359
- Joined: Sat Feb 25, 2006 11:09 am
- Location: Sant Cugat del Vallès (Barcelona, Spain)
- Contact:
Re: Accessing Return() values
Let me guess, did you use "show screen" instead of "call screen"?Abeiramar wrote:I would like to ask something about the Return() thingy...
When I'm on a screen and I create this button:It brings me back to the main game menu instead of the label where I was at ! Why is that?Code: Select all
screen blah: textbutton _("Return") action Return()
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
Re: Accessing Return() values
Interesting! However, it doesn't seem to work ...
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 !
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 >_>
Are you sure it's just "call screen" ?
Thank you very much for answering anyway !
-
- Miko-Class Veteran
- Posts: 758
- Joined: Tue Jun 22, 2010 12:54 am
- Completed: Christmas
- IRC Nick: DragoonHP
- Location: Zion Island, Solario
- Contact:
Re: Accessing Return() values
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...
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...
-
- Veteran
- Posts: 359
- Joined: Sat Feb 25, 2006 11:09 am
- Location: Sant Cugat del Vallès (Barcelona, Spain)
- Contact:
Re: Accessing Return() values
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:
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
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"
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
Re: Accessing Return() values
Thanks for the answers . 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
instead.
It works the way I want now~
I followed your advice and put
Code: Select all
textbutton _("Return") action Jump("odd_man") xpos 58 ypos 500
It works the way I want now~
-
- Veteran
- Posts: 359
- Joined: Sat Feb 25, 2006 11:09 am
- Location: Sant Cugat del Vallès (Barcelona, Spain)
- Contact:
Re: Accessing Return() values
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:
but then add the jump after calling (and returning from) the screen:
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
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
Code: Select all
call screen pictures
jump odd_man
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
Who is online
Users browsing this forum: Bing [Bot]