954,515 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help with this code,please

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
			self.posicion=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 "", line 1, in
p1.recibir_ataque()
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
p1.recibir_ataque()

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 :/

Nachodsk
Newbie Poster
3 posts since Aug 2011
Reputation Points: 7
Solved Threads: 0
 

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):
...
SgtMe
Nearly a Posting Virtuoso
1,205 posts since Oct 2009
Reputation Points: 68
Solved Threads: 85
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: