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.
-
hapciupalit
- Regular
- Posts: 52
- Joined: Tue Nov 13, 2018 6:00 am
-
Contact:
#1
Post
by hapciupalit » Wed Nov 25, 2020 12:38 pm
Hi there, I have a label and a screen with a button. When the button is pressed I call a function which checks for something and if that is True then it should return back in the label.
Code: Select all
label test:
"something goes here"
call screen test_screen()
"I want to be back here"
screen test_screen():
imagebutton:
auto "path_to_url"
action Function(testFunc)
init python:
def testFunc():
if something:
# what should I do here to leave the screen and go back where I left.
# I could do renpy.jump("test") but that will go back to "something goes here"
# while in my case I would like to have something similar to action Return() which
# would have return me to "I want to be back here"
else :
#something else
Thank you!
-
_ticlock_
- Veteran
- Posts: 391
- Joined: Mon Oct 26, 2020 5:41 pm
-
Contact:
#2
Post
by _ticlock_ » Wed Nov 25, 2020 2:54 pm
Hi,
hapciupalit,
Why not use another label or local label:
Code: Select all
label test:
"something goes here"
call screen test_screen()
label .something:
"I want to be back here"
screen test_screen():
imagebutton:
idle "P1.jpg"
action Function(testFunc)
init python:
def testFunc():
if something:
renpy.jump("test.something")
else:
pass
-
hell_oh_world
- Miko-Class Veteran
- Posts: 777
- Joined: Fri Jul 12, 2019 5:21 am
- Projects: The Button Man
- Organization: NILA
- Github: hell-oh-world
- Location: Philippines
-
Contact:
#3
Post
by hell_oh_world » Wed Nov 25, 2020 3:08 pm
If the function in the Function action returns value other than None, then it will end the interaction and return that value.
Code: Select all
init python:
def myReturn(): return True # return any value other than None to end the interaction.
screen test():
texbutton "Return" action Function(myReturn)
label start:
call screen test
"Continuation... Return value is [_return]"
-
Remix
- Eileen-Class Veteran
- Posts: 1628
- Joined: Tue May 30, 2017 6:10 am
- Completed: None... yet (as I'm still looking for an artist)
- Projects: An un-named anime based trainer game
-
Contact:
#4
Post
by Remix » Wed Nov 25, 2020 3:34 pm
Code: Select all
init python:
def testFunc():
if some_success_condition:
return "success"
## returning a NOT None value is the same as Return() ... even return False or return 0 will be ok
else:
# returning None will keep the called screen there as though nothing had happened
return None
The value returned incidentally can be later displayed or checked in the global _return variable's value
-
hapciupalit
- Regular
- Posts: 52
- Joined: Tue Nov 13, 2018 6:00 am
-
Contact:
#5
Post
by hapciupalit » Thu Nov 26, 2020 10:21 am
_ticlock_ wrote: ↑Wed Nov 25, 2020 2:54 pm
Hi,
hapciupalit,
Why not use another label or local label:
Code: Select all
label test:
"something goes here"
call screen test_screen()
label .something:
"I want to be back here"
screen test_screen():
imagebutton:
idle "P1.jpg"
action Function(testFunc)
init python:
def testFunc():
if something:
renpy.jump("test.something")
else:
pass
Because this is a minigame that can start from different situations in the game.
I have a scene in which people come to my coffeeshop and ask for a coffee. Then I call my screen and then when I'm done preparing the coffee I should return back to the person giving, however the problem with more labels is the fact that I will then have to create a label for each situation and each customer. While if I can return where I left it solves plenty of writing.
-
hapciupalit
- Regular
- Posts: 52
- Joined: Tue Nov 13, 2018 6:00 am
-
Contact:
#6
Post
by hapciupalit » Thu Nov 26, 2020 10:23 am
hell_oh_world wrote: ↑Wed Nov 25, 2020 3:08 pm
If the function in the Function action returns value other than None, then it will end the interaction and return that value.
Code: Select all
init python:
def myReturn(): return True # return any value other than None to end the interaction.
screen test():
texbutton "Return" action Function(myReturn)
label start:
call screen test
"Continuation... Return value is [_return]"
Cheers. This solved my problem.
By the way. Is there a way to know what my screen returned?
Something like this:
Code: Select all
label test:
"Hi there"
call screen test()
"This is what my test returned : [???]"
Right now In my function I have something like this:
Code: Select all
def testFunc():
if something:
variable = True
return True
else:
variable = False
return False
So getting rid of the variable would be cool.
-
RicharDann
- Veteran
- Posts: 284
- Joined: Thu Aug 31, 2017 11:47 am
-
Contact:
#7
Post
by RicharDann » Thu Nov 26, 2020 10:39 am
hapciupalit wrote: ↑Thu Nov 26, 2020 10:23 am
By the way. Is there a way to know what my screen returned?
hell_oh_world already demonstrated it, but there's a built-in special variable called
_return that automatically stores whatever is returned from a screen or a return statement.
Code: Select all
label start:
call screen test
"Continuation... Return value is [_return]"
You can also use the python equivalent of call screen and store the result directly to a variable:
Code: Select all
default var = None
label start:
$ var = renpy.call_screen('test')
"Return value is [var]"
Last edited by
RicharDann on Thu Nov 26, 2020 10:43 am, edited 1 time in total.
The most important step is always the next one.
-
gas
- Miko-Class Veteran
- Posts: 838
- Joined: Mon Jan 26, 2009 7:21 pm
-
Contact:
#8
Post
by gas » Thu Nov 26, 2020 10:39 am
Use just after the call line
Code: Select all
call screen test
$ stored = _return
and stored will be equal the returned value.
...as the guy writing the same time as me correctly said...
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.
10 ? "RENPY"
20 GOTO 10
RUN
-
hapciupalit
- Regular
- Posts: 52
- Joined: Tue Nov 13, 2018 6:00 am
-
Contact:
#9
Post
by hapciupalit » Thu Nov 26, 2020 10:47 am
RicharDann wrote: ↑Thu Nov 26, 2020 10:39 am
hapciupalit wrote: ↑Thu Nov 26, 2020 10:23 am
By the way. Is there a way to know what my screen returned?
hell_oh_world already demonstrated it, but there's a built-in special variable called
_return that automatically stores whatever is returned from a screen or a return statement.
Code: Select all
label start:
call screen test
"Continuation... Return value is [_return]"
You can also use the python equivalent of call screen and store the result directly to a variable:
Code: Select all
default var = None
label start:
$ var = renpy.call_screen('test')
"Return value is [var]"
Thank you very much!
-
hapciupalit
- Regular
- Posts: 52
- Joined: Tue Nov 13, 2018 6:00 am
-
Contact:
#10
Post
by hapciupalit » Thu Nov 26, 2020 10:47 am
gas wrote: ↑Thu Nov 26, 2020 10:39 am
Use just after the call line
Code: Select all
call screen test
$ stored = _return
and stored will be equal the returned value.
...as the guy writing the same time as me correctly said...
Thanks. It works perfectly!
Users browsing this forum: Google [Bot]