Monday, August 10, 2015

Variables on Scratch

Variables are used whenever a value must be stored — i.e., if a project required the user to input a name and then remember that name, the name would be stored in a variable. With this, the name can be retrieved at any time; all the project has to do is check the value (which is the name).

The look of the variable can be changed in to three forms: The normal readout, the large readout, and the slider. The form of the variable can be changed by double-clicking or right-clicking it and selecting the option that is wanted, or clicking it using the grow/shrink sprite tool.

The following example illustrates one use of  one variable. The variable name is "Flying".

The following scripts control the value of the variable "Flying", the vertical movement of the helicopter and the land/crash speed. Two different forces are "simulated" in this really simple project: the propellers thrust (adding a positive value to "Flying") and the gravity force (constantly changing "Flying" by a negative value).

The actual movement of the helicopter is controlled by the "Change y by" block, where the standard value is replaced by the value of the variable.


Post a Comment