[Tutor] Combat Error

Don Jennings dfjennings at gmail.com
Mon Jul 8 01:15:42 CEST 2013


On Jul 7, 2013, at 6:40 PM, Jack Little wrote:

> When the player of my game fire his/her cannon, it is supposed to get rid of some of the enemy's health. It does not. I have no clue what the error is, so I need help. 
>         if combat.lower()=="fire cannon 1":
>             print "Fired!"
>             cannonhealth-attack
>             print "Enemy health=",cannonhealth

<snip a lot of unnecessary code>

Let's see if I can help you ask a better question.

As you can see from your output, the name "cannonhealth" refers to an object which is different than what you expect. So, your question might be, "How do I get a name to refer to a different object? I thought I could just use subtraction." At that point, you might ask, "Well, how did I get that name to refer to an object (75 in this case) in the first place?" Therein, lies your answer. (Hint:  assignment.)

Take care,
Don



More information about the Tutor mailing list