renpy.return from screen

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
hapciupalit
Regular
Posts: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

renpy.return from screen

#1 Post by hapciupalit »

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!

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: renpy.return from screen

#2 Post by _ticlock_ »

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

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: renpy.return from screen

#3 Post by hell_oh_world »

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]"

User avatar
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:

Re: renpy.return from screen

#4 Post by Remix »

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
Frameworks & Scriptlets:

hapciupalit
Regular
Posts: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: renpy.return from screen

#5 Post by hapciupalit »

_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: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: renpy.return from screen

#6 Post by hapciupalit »

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.

User avatar
RicharDann
Veteran
Posts: 286
Joined: Thu Aug 31, 2017 11:47 am
Contact:

Re: renpy.return from screen

#7 Post by RicharDann »

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.

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: renpy.return from screen

#8 Post by gas »

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: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: renpy.return from screen

#9 Post by hapciupalit »

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: 56
Joined: Tue Nov 13, 2018 6:00 am
Contact:

Re: renpy.return from screen

#10 Post by hapciupalit »

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!

Post Reply

Who is online

Users browsing this forum: bonnie_641, Google [Bot], NeonNights