Increase health by 1 as bonus related to score! Unit 3 CSD

My student wants the health to increase by one when his score gets to 19. We are not sure how to limit this increase to just 1 when it doesn’t involve a sprite. ! Code below

Hi @lwilliams1,

The easiest way to do this is to set another variable called “canChange” or something. It is a boolean variable set to true initially and it then toggles to false as soon as health is decreased by one. You can toggle it back to true on some other condition if you need to. So, health can decrease
if (score == 19 && canChange == true) {
health = health-1; canChange = false; //toggles to false so only 1 points will be added
}.

Hope that makes sense!
~Michelle

Thanks Michelle - I will give it a try!

So this is a little complicated for me sorry Michelle - this is what we tried and we were not successful. Could you take a look again please.

Code here

@lwilliams1,

Looks like on Line 69, true was misspelled.
Also, on line 70, that should be split into two lines.

health = health +1; (adds 1 to the health score)
canchange = false; (resets the canchange variable to false)

If you try those and still are not seeing what you want, click on the share button and send us the link you get and we can look at it further!

Best wishes!

Mike

Oh my goodness :woman_facepalming:- thank you!

Thank you it works! I have a very happy student :slight_smile:

2 Likes