Is it possible to make a variable passed to a function global inside the function?

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
span4ev
Regular
Posts: 105
Joined: Fri Jul 08, 2022 9:29 pm
itch: rpymc
Contact:

Is it possible to make a variable passed to a function global inside the function?

#1 Post by span4ev »

I want to pass variables inside a function, but they won't change because they need to be made global.
Before this, I used a simple way:

Code: Select all

1. setVariable()
2. def my_func():
	global money, ...(other variables)
But it's more convenient to do it like this:

Code: Select all

def my_func(x):
	
	global x

	x += 1

my_func(money)
But I can't make them global inside the function. Is it possible?

laure44
Regular
Posts: 84
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Is it possible to make a variable passed to a function global inside the function?

#2 Post by laure44 »

I'm not even sure that's possible, but it would probably be safer to just use return.

Code: Select all

def my_func(x):
    return x + 1

money = my_func(money)

Post Reply

Who is online

Users browsing this forum: Google [Bot]