Friday 13 September 2013

Creating variables

Today we learned how to create variables such as timers and health. Its best to add this to the stage background to keep it constantly visible.
"Health" is just a variable set to a certain number, in this case it is called health and set to 100.

Scratch code

With the addition of the second block of commands, it will broadcast a message to the player once their health has droped to zero that they have lost.

Scratch code

This is an example of a health boosting varible. Once applyed to a sprite and the proper sequence is acheved it will increase the players health to a maxium of 100 and then disappear for a set amount of time.

Scratch code

This is my final example of a varible, a timer. Time is not concept in scratch commands. This is why a varible, time, must be created. To simulate a timer ticking down we first set the time varible to 200 in this case. Then we add a band that will continue the contained code forever. We then add code to change the time varible by -1 and to wait for 1 second intervils to repeat the prosess.

No comments:

Post a Comment