[Python] VS Python keeps throwing type and name errors for CYOA Game

Discussão em 'Python' iniciado por Stack, Maio 16, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to make a healing system for a CYOA game as part of a school assessment, but the code just doesn't work. it refuses to work at all, and it's kinda frustrating considering this game worth 30% of my grade. any help? here's the code for the healing function, its bad ik, i had to make it from scratch. i can dump the full 200 ish lines if needed. this is done in python, not pygame btw.

    def healthuse(self):
    startinghealthuse = 3
    healthuse = 2
    if healthuse <= 0:
    print('you have run out of healing, find more by exploring the local area')

    else:
    hero.health = hero.health + 2
    healthuse = healthuse - 1
    print('you now have',hero.health, ' out of', hero.startinghealth)
    print('You now have',healthuse, 'out of', startinghealthuse,' healing supplies.')
    if hero.health > hero.startinghealth:
    hero.health = hero.startinghealth
    else:
    hero.health = hero.health


    It keeps throwing type-errors no matter what I do, I tried making it its own class, didn't work. tried defining the max amount and the current as an integer, nope. it's meant to trigger when the player types "heal", and healing items are gained when the player explores the area. it's meant to have a max available healing items of 3 and shouldn't heal when there are no healing items left. it keeps throwing type-errors and name-errors. here's the last error i got from it before it closed:

    "NameError: name 'healthuse' is not defined. Did you mean: 'self.healthuse'?"

    Continue reading...

Compartilhe esta Página