[Solved]What exactly do the "pass" and "return" keywords do?

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
squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

[Solved]What exactly do the "pass" and "return" keywords do?

#1 Post by squark » Sun Jan 27, 2013 9:18 am

So, yeah; topic title.
It may seem like a simple question considering how long I've been active on these forums.
But for the life of me, I can't make my brain come up with a reasonable explanation.

Before I start throwing it into my code, I just want to be clear.

Something simpler as well; the "return" keyword baffles me, especially on its own, when it's not returning a variable.

EDIT: In clear English, please.
Last edited by squark on Tue Jan 29, 2013 7:00 am, edited 1 time in total.
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

User avatar
Ayutac
Regular
Posts: 150
Joined: Thu Oct 18, 2012 2:23 pm
Projects: Pokémon Dating Sim
Organization: A Breeze Of Science
Deviantart: Ubro
Location: Mayence, Germany
Contact:

Re: What exactly do the "pass" and "return" keywords do?

#2 Post by Ayutac » Sun Jan 27, 2013 3:53 pm

"pass" does nothing. It is indeed the clear instruction to do nothing. There are situations when this comes in handy, see example in next post (thanks, KimiYoriBaka).
Constructs like if always need a command after them, but if you literally want nothing to happen but have to give a command, pass is used. I just don't know if it's used in Python or Ren'Py xD

As for "return", it has different meanings. If used in Ren'Py, it returns the executing code to the point where you last used

Code: Select all

call labelName
where "labelName" is – who would have guessed it – the name of a label. However, if you have no "call" running at the moment, it returns to the game menu, so the actual game will be ended. Without asking to save, I might add. This return has a Python equivalent (end of post).
In Python "return" behaves different. It will simply return from the currently executing method to where the method was called from, occasionally returning a value which can be read. If no value is returned, you better try not to read anything.

Any questions left?
Last edited by Ayutac on Mon Jan 28, 2013 12:30 am, edited 1 time in total.
Up next: An original, open source, text-based Dating Sim. Stay tuned ;)

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: What exactly do the "pass" and "return" keywords do?

#3 Post by KimiYoriBaka » Sun Jan 27, 2013 7:01 pm

just thought I'd add an example of "pass" that's a bit more useful and relevant.

if you have a set of choices that may or may not actually cause something to happen, then you can use "pass" to tell renpy that you don't want a choice to do anything.

Code: Select all

menu:
    j "hey hey, watch me juggle these knives!!"

    "Watch him juggle":
        "The juggler successfully juggles a bunch of knives as I stare in awe."

    "Ignore him and continue walking":
        pass

"We continue walking."

User avatar
squark
Veteran
Posts: 277
Joined: Fri Aug 17, 2007 9:59 am
Completed: Tour de Pharmacy (Proofreader), The Abandoned Land: Book One (Proofreader)
Projects: Raven Hollow (Core Coder, Proofreader), The Universal Hope (Core Coder, Proofreader)
Organization: FlareBlue Entertainment
Location: Always somewhere behind you...
Contact:

Re: What exactly do the "pass" and "return" keywords do?

#4 Post by squark » Tue Jan 29, 2013 6:59 am

Thanks, guys. This makes it very easy to follow ^^
Without communication, nothing is possible.
"All we see or seem
Is but a dream within a dream.

I stand amid the roar
Of a surf-tormented shore"
-- Edgar Allen Poe, "A Dream Within A Dream"
Current Projects:
Universal Hope Stalled
Raven Hollow (on hold for now)
Peace and Love,
Squark

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_