class Personaje(object):
	def __init__(self,vida,posicion,velocidad):
		vida = None
		posicion = None
		velocidad = None
		recibir_ataque = None
	def recibir_ataque(vida):
		recibir_ataque in range(1,100)
		vida - recibir_ataque
		print "La vida actual del personaje es de", vida, " Luego de haber recibido", recibir_ataque, " de dano"
	def excepcionVida(vida):
		if vida <= 0:
			print "El personaje ya esta muerto..."
	def moverPosicion(posicion,velocidad):
		if velocidad >= 1 and velocidad <= 5:
			print "Te quedas quieto,no puedes movilizarte"
		if velocidad >= 6:
			print "A donde deseas movilizarte?"
			posicion=input("Norte,Sur,Este u Oeste?"), posicion
			posicion = ["Norte","Sur","Este","Oeste"]

Hello! :)

I'm having a little problem with this code i recently made to test myself.

Everything goes very well, i can import everything fine, i create the object Personaje() but when i want to use the FUNCTION recibir_ataque()

It says:

Traceback (most recent call last):
File "<pyshell#76>", line 1, in <module>
File "C:\Python27\rpg.py", line 9, in recibir_ataque
recibir_ataque in range(1,100)
NameError: global name 'recibir_ataque' is not defined

I don't know really which is the problem of that, i know there's a post about this in the forums.. but i try that and nothing :(

I want that function to work like this, for example at first time when i create the object

p1 = Personaje(here i write the attributes like VIDA,POSICION,VELOCIDAD)

once that ready i try to do

It should says something like "Pierdes 358 puntos de vida" and then when i want to check the status of VIDA (Health) from the Personaje it says the VIDA it has now after the function recibir_ataque() it is Vida - recibir_ataque()

Don't know why it doesnt work!
Any help will be nice! Thanksss :)

P.S: Sorry for my english :/

5 Years
Discussion Span
Last Post by SgtMe

You should put "self" in the arguments for all the functions in the class.

def recibir_ataque(self, vida):
def excepcionVida(self, vida):
def moverPosicion(self, posicion,velocidad):

Edited by SgtMe: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.