python - NameError: name ... is not defined -
i trying make rpg game in python 2.7 but, run problem. try pygame draw starting_money , stam on screen.(i have them in init function in player_1.py.) when run it, says starting_money , stam not defined. (yes, have imported player_1 via player_1 import *.) here example of code:
import pygame pygame.locals import * player_1 import * monster import * background_colour = (0,0,0) (width, height) = (800, 800) screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('rpg game') screen.fill(background_colour) pygame.display(starting_money(500), stam(100)) pygame.display.flip() running = true while running: event in pygame.event.get(): if event.type == pygame.quit: running = false`
and here example of player_1.py
import pygame pygame.image.load('player1.png') class hero: def __init__(self, hp, alive, starting_money, stamina, player1_sprite, player1, run): self.starting_money = starting_money self.money = 500 self.hp = 1 self.hp = hp self.alive = true self.stam = stamina self.stamina = 100 self.ps = player1_sprite self.run = run player1_sprite = 'player1.png' def attacked(self, hp): if self.hp >= 1: self.alive = true elif self.hp < 1: self.alive = false def stam(self, stamina): if self.stam > 0: self.run = true elif self.stam <= 0: self.run = false def money(self, money): pass
i figured out, responding guys.
you need instantiate hero hero class wrote. create hero 500 starting money, 100 stamina , 100 hp, call:
galavant = hero(100, 'placeholder', 500, 100, 'placeholder', 'placeholder', 'placeholder')
then later calling:
galavant.starting_money
, galavant.stam
should yield 500 , 100, respectively.
Comments
Post a Comment