Following a tutorial thought i was clever enough to play around lol

so making a rpg battle system following the tutorial but it only makes attacks so i thought creating a heal spell would be good practice and help me understand better this is what i got

class

class Person:
    def __init__(self, hp, mp, sp, atk, df, magic, skills):
        self.maxhp = hp
        self.hp = hp
        self.maxmp = mp
        self.mp = mp
        self.maxsp = sp
        self.sp = sp
        self.atkL = atk - 10
        self.atkH = atk + 20
        self.df = df
        self.magic = magic
        self.skills = skills
        self.actions = ["Attack", "Magic", "Skills"]

    def generate_damage(self):
        return random.randrange(self.atkL, self.atkH)

    def generate_spell_damage(self, i):
        mgl = self.magic[i]["dmg"] - 5
        mgh = self.magic[i]["dmg"] + 5
        return random.randrange(mgl, mgh)


    def generate_heal_spell(self, i):
        mgl = self.magic[i]["restore"] - 5
        mgh = self.magic[i]["restore"] + 5
        return random.randrange(mgl, mgh) 
    

main code

from classes.game import Person, bcolors

magic = [{"Spell Name": "Fire", "Spell Cost": 10, "dmg": 60},
         {"Spell Name": "Spark", "Spell Cost": 10, "dmg": 60},
         {"Spell Name": "Cold", "Spell Cost": 10, "dmg": 60},
         {"Spell Name": "Heal", "Spell Cost": 7, "restore": 45}]

skills = [{"Skill Name": "Slash", "Skill Cost": 6, "dmg": 23},
          {"Skill Name": "Bash", "Skill Cost": 8, "dmg": 37},
          {"Skill Name": "Pierce", "Skill Cost": 4, "dmg": 17},
          {"Skill Name": "God Clap", "Skill Cost": 67, "dmg": 337}]


player = Person(500, 220, 100, 70, 45, magic, skills)

print(player.generate_spell_damage(0))
# print(player.generate_heal_spell(10))

type or paste code here

any help on where i messed up would be appreciated

I tested your code out, and the only thing I needed to do was add: import random to your Person module. But other than that, all 3 functions seem to work. You may want to add a safeguard against incorrect i arguments in the spell functions to avoid KeyErrors.

Edit: I should note I didn’t break this up into different scripts like you have, just ran it in one iPython go.

1 Like

thanks. turns out the tut was going to go over healing spells anyway. lol but it was good to know i could freestyle it a bit. and i will remember the backtick thing next time sorry