Calling a label w/ arguments... using 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
monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Calling a label w/ arguments... using python

#1 Post by monele »

Code: Select all

label myfunction (myarg):
    return True
#
How could I call this, pass arguments and get a value in return, using a python function?
Something like...
$ res = call_label("myfunction", somevar)

Or I could do with a way to call a function by giving a string for its name. Is this possible?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: Calling a label w/ arguments... using python

#2 Post by PyTom »

Code: Select all

$ funcname = "myfunction"

call expression funcname(myarg)
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Calling a label w/ arguments... using python

#3 Post by monele »

In Python :). I'm in a big python loop so I can't suddenly pull out some Ren'Py code. But I made it work using call_in_new_context since it accepts arguments and does send back the return value. I only noticed one little strange thing : making the returned variable dynamic (with renpy.dynamic) prevents the variable from being returned (it tries to return a variable with the same name from the global scope). Of course, this is all using 6.3.0d, so... maybe it was fixed ^^;.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
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: Calling a label w/ arguments... using python

#4 Post by PyTom »

Hm... this bug was present in the current version of Ren'Py as well, but it will be fixed in the next. Let me know if you want the updated file, so you can develop assuming then new behavior.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

monele
Lemma-Class Veteran
Posts: 4101
Joined: Sat Oct 08, 2005 7:57 am
Location: France
Contact:

Re: Calling a label w/ arguments... using python

#5 Post by monele »

Mm, it's okay. I'm using a single variable named "dres" that I'll be sure not to use anywhere else ^_^. And if it does annoy me, I'm sure the next version will have been released by then :).

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]