calling a dynamic variable within a class function
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.
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.
-
Theh0llowone
- Newbie
- Posts: 2
- Joined: Fri May 06, 2022 1:43 pm
- Contact:
calling a dynamic variable within a class function
Hi, this is my first post here so I'm sorry if I screw up any rules/formatting,
I'm also sorry if the title is unclear as to what I'm asking, but even I don't know what to call it,
What I generally want to know is if there is a way to have the variables in a function of a class be changed by the input, for example having something along the lines of info.update (Info, name of the variable).
Just to be able to not have to have a function to update each individual variable.
Thank you for taking the time to read about my issue.
I'm also sorry if the title is unclear as to what I'm asking, but even I don't know what to call it,
What I generally want to know is if there is a way to have the variables in a function of a class be changed by the input, for example having something along the lines of info.update (Info, name of the variable).
Just to be able to not have to have a function to update each individual variable.
Thank you for taking the time to read about my issue.
- RicharDann
- Veteran
- Posts: 284
- Joined: Thu Aug 31, 2017 11:47 am
- Contact:
Re: calling a dynamic variable within a class function
I don't fully understand your question, but if you want to change the value of an object property, you can just assign the new value with an equal sign (=):
Code: Select all
init python:
class Person():
def __init__(self):
self.name = "Unknown"
default john = Person()
label start:
"Default name: [john.name]"
$ john.name = "John Doe"
"New name: [john.name]"
The most important step is always the next one.
-
Theh0llowone
- Newbie
- Posts: 2
- Joined: Fri May 06, 2022 1:43 pm
- Contact:
Re: calling a dynamic variable within a class function
Ahh, sorry my explanation wasn't the greatest, thanks for trying to answer anyway, I'm trying to see if it's possible to have one function that takes two arguments, one that is the information to be stored, and the other being the variable to store it in, for example, something like
Code: Select all
class LoveInterest(object):
def __init__ (self, Affection, Friendship):
self.Affection = Affection
self.Friendship = Friendship
@property
def UpdateInfo(self, info, variablename):- Ocelot
- Eileen-Class Veteran
- Posts: 1883
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: calling a dynamic variable within a class function
Code: Select all
class Test:
def update_info(self, variable, value):
setattr(self, variable, value)
# . . .
$test = Test()
$test.update_value("level", 555)
"Level is :[text.level]"< < insert Rick Cook quote here > >
Who is online
Users browsing this forum: Bing [Bot]