[Tutor] True to False and Other things!

Dave Angel davea at davea.name
Thu Jun 27 15:45:51 CEST 2013


On 06/27/2013 09:27 AM, Jack Little wrote:
> In my game, I am trying to make it so when the enemy's health equals 0, the player advances. I used a while statement and a true or false variable. When the enemy health is less than or equal to 0, the program exits the while statement. It does not work. It keeps going. How could I fix this?
>
>

You could try changing the value of that true/false variable inside the 
loop.  Have you made the dozens of changes suggested by various people 
here?  And as another hint, do you understand what local variables are, 
and that local variables in one function do not normally have any effect 
on local variables in another?

I suggest you temporarily forget the larger program, and write a small 
one that demonstrates your symptom.  Write a while-loop inside a 
function that tests some variable.  Write a body of that loop which 
changes the variable, presumably when some condition changes.  And see 
if it ever terminates.  If it shows the same symptom, and you cannot see 
the reason, then post it here.  The entire program.  And explain clearly 
what you expected and in what way it did something different.

In case you can't tell, the explanation you gave above was not clear. 
You said that the program exits the loop, and then you said the loop 
kept going.  Presumably one of them was an EXPECTATION and the other was 
reality.  Of course, there are some other things you could have meant, 
like that the program kept going after the loop.  But I doubt it.

-- 
DaveA


More information about the Tutor mailing list