Reputation: 1
I've been working with Ren'Py engine, a simple engine for visual novels using Python to do stuff. I came across this problem and dunno what to do, anybody can gimme a hand?
bar: StaticValue(variable, value)
Bar creates a bar representing variable, with the maximum value of value. I will not mention value further, as it is irrelevant to my question.
I am trying to use Used as variable, meaning Used is variable being represented. Used however, doesn't have value in integer. Used is a variable with a value of "Skill1" or "Skill2"
Skill1 and Skill2 are variables with integers, and THEY are the ones I want to represent by the bar.
So, what I want in the end is StaticValue(Skill1, value) OR StaticValue(Skill2, value), depending on the value of Used (There is If predated to define this).
Another try at the explanation:
What Python THIKS RIGHT NOW:
bar: StaticValue(Used). Bar is supposed to represent variable Used.
What I WANT Python TO THINK:
bar: StaticValue(Used). Used is a variable with a value of "Skill1". Bar is supposed to represent Skill1, as this results in StaticValue(Skill1).
I took a second try on that explanation, hopefully better now. Any help is appreciated.
As a reaction to User2589273's answer, for better overview: The 4) would be exactly what I want/need, but it gives me unspecified error now. What I did was:
python:
if InTeaching == "Skill1":
UsedSkill = "1"
elif InTeaching == "Skill2":
UsedSkill = "2"
elif InTeaching == "Skill3":
UsedSkill = "3"
else:
pass
dict = {1: 'Skill1Value', 2: 'Skill2Value', 3: 'Skill3Value'}
Followed by:
bar:
value StaticValue(dict[UsedSkill], 10)
So if InTeaching == Skill1, UsedSkill will be set to 1. Later, in the bar, UsedSkill will be matched by the dictionary to fill in Skill1Value, variable that is supposed to be present in the StaticValue. It works in my head, but python gives me error on line with "bar:".
Upvotes: -3
Views: 727
Reputation: 2467
Not too sure what you are asking but here are my four guesses:
1) assigning a variable using a string name / string from other variable:
dict = {'variable_name':value}
add to locals().update(dict)
2) Supplying an argument consisting as two parts which have already been pre-defined:
a = [b,c]
barstuffs(a)
3) something to do with making a class that can take on certain values: Have a read through https://docs.python.org/2/tutorial/classes.html
4) dictionary use:
dict = {0: 'skill1', 1: 'skill2'}
used = 1
dict[used] will give 'skill2'
Upvotes: 0