"Charname" was defined earlier by the user, the same with STR, AGI, HP, MP and so on, using Renpy. Since I'm working on a RPG, the stats will be changing from time to time. The variable "Charname" works just as intended.
The problem begins when I try to change the values in between parentheses to variables, for example, when I change Attack = Skill("Attack", (mp cost), [AGI], [STR]), from fixed values to variables, I get syntax errors. I've tried using brackets, parenthesis and quotes, nothing works. Since I'm going to be using a lot of variables, I want to learn how to properly pass Renpy variables to Python.
Thanks in advance. Here is the code, if someone wants to look at it. It's not mine, I've found it using the search function on the forum.
Code: Select all
init -1 python:
class Fighter():
def __init__(self, name, max_hp, max_mp, skills):
self.name = name
self.max_hp = max_hp
self.hp = max_hp
self.max_mp = max_mp
self.mp = max_mp
self.skills = skills
def auto_select(self):
while True:
selected = renpy.random.choice(self.skills)
if selected.cost<self.mp:
return selected
def defence(self):
if user.skill.hit<renpy.random.randint (0,100):
renpy.say (adv, ("%s dodged the attack" %self.name))
return
else:
self.hp -= user.skill.power
renpy.say (adv, ("%s got %d damage" %(self.name, user.skill.power)))
return
class Skill():
def __init__(self, name, cost, hit, power):
self.name = name
self.cost = cost
self.hit = hit
self.power = power
def use(self):
user.mp -= self.cost
renpy.say (adv, ("%s used %s" %(user.name, self.name)))
target.defence()
return
def battle(win, lose):
global player, enemy, user, target
renpy.show_screen("battle_ui", zorder="2")
while True:
renpy.say (adv, "Skill select", interact=False)
player.skill = renpy.call_screen("skill_select")
enemy.skill = enemy.auto_select()
user = player
target = enemy
user.skill.use()
if target.hp<1:
renpy.jump(win)
user = enemy
target = player
user.skill.use()
if target.hp<1:
renpy.jump(lose)
screen skill_select:
vbox xpos .05 ypos .3:
for i in player.skills:
if i.cost <= player.mp:
textbutton "[i.name]" action Return (value=i)
else:
textbutton "[i.name]"
screen battle_ui:
frame xmaximum 200 xanchor 1.0 xpos 0.99 yalign 0.10:
has vbox
hbox:
text "[enemy.name]"
hbox xfill True:
text "HP"
text "[enemy.hp]/[enemy.max_hp]" xalign 1.0
hbox xfill True:
text "MP"
text "[enemy.mp]/[enemy.max_mp]" xalign 1.0
frame xmaximum 200 xpos 0.01 yalign 0.10:
has vbox
hbox:
text "[player.name]"
hbox xfill True:
text "HP"
text "[player.hp]/[player.max_hp]" xalign 1.0
hbox xfill True:
text "MP"
text "[player.mp]/[player.max_mp]" xalign 1.0
label start:
$ Attack = Skill("Attack", 0, 50, 10)
$ Talents = Skill("Talents", 15, 100, 20)
$ Wait = Skill("Wait", 0, 100, 0)
$ player = Fighter ("Charname", 50, 50, [Attack, Talents, Wait])
$ enemy = Fighter ("Goblin", 50, 50, [Attack, Talents])
$ battle("win", "lose")
label win:
"you won"
return
label lose:
"you lost"
return