Class Error: Please Help

Whenever I reach a certain point in my game, it gives an error when I print out a class object, even though it has a __str__ function. I’m not sure why this is happening.
Link: https://replit.com/@IronCodem/Pokemon-RPG-Game?v=1
Steps to recreate the bug: Input your username, select your Pokémon and type “find”. Then type “fight”.

Identation is wrong:

image

2 Likes

good catch but it still doesn’t change the output :confused:

I noticed something:

blastoise = Pokemon("blastoise",268,144,[WATER_PULSE, AQUA_TAIL, HYDRO_PUMP, SKULL_BASH],['water'])

def Caterpie():
	hp = 200
	speed = 85
	moveset = [TACKLE, BUG_BITE]
	type = ['bug']

Starting from Caterpie, your functions are being instantiated as Pokemon objects. The Pokemon class has a __str__ method but your functions that represent each Pokemon do not.

You should instantiated them as Pokemon objects:

Caterpie = Pokemon("Caterpie", 200, 85, [TACKLE, BUG_BITE], ['bug'])

Don’t know why you change them mid-way though

3 Likes

they were all originally functions but I converted them to class objects – just haven’t finished converting all of them. That’s not the problem though cause they aren’t in the list that allows them to be chosen

I tried to reacreate the steps and the fight option is working. Can you show the error you are getting?

Oh, that explains.

If you try to concatenate a string with a non-string (like an instance of a class), you’ll get a TypeError .

Convert starter to string and you are good to go.

print(pale + str(starter) + white + " go!")
2 Likes

Do the same thing for the other ones too.

I’ve never had to o that before, but I guess somethings different this time around! Anyways, thanks for the help with everything!

In Python, the + operator is used for concatenating strings.

In your case starter is a object not a string.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.