Return() in python

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
pucedragonlord
Regular
Posts: 159
Joined: Wed May 09, 2012 2:49 am
Projects: The Diviner
Organization: Two Crowns Entertainment
Location: Now: Charlottesville, VA
Contact:

Return() in python

#1 Post by pucedragonlord » Mon Sep 29, 2014 9:18 am

I'm trying to get a menu to close after performing an action, but only if the action is successful. THe logical thing to do would be include a Return() command in the python where the action is defined, but I can't seem to make it work. What is the Python equivalent of the Return() action, or how do I call it from within Python?

Alternatively, when stringing actions together as a list, how does RenPy handle them? If make the second action a conditional, will it check the condition before running the first action, or will it run the first action before checking?

so would, for example:

Code: Select all

action [SetVariable("foo", 1), If(foo == 1, SetVariable("bar", 1), SetVariable("bar", -1))]
print bar
spit out 1 or -1?
The more you know

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Return() in python

#2 Post by PyTom » Mon Sep 29, 2014 9:22 am

The If function runs when the action list is first created. So what you actually get (assuming foo == 0 to start) is:

Code: Select all

.. action [ SetVariable("foo", 1), SetVariable("bar", -1) ]
The Return() action - with no arguments - is equivalent to placing the following code at the end of your action:

Code: Select all

                if main_menu:
                    ShowMenu("main_menu")()
                else:
                    return True
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot]