Change () by () (block)
|Change () by ()|
The Change () by () block is a Variables block and a Stack block. The block will change the specified variable by a given amount. If the variable is a string and not a number, it is set to the quantity the variable was to be changed by (casting the string to 0).
Prior to Scratch 1.3, this block didn't have a drop-down input listing the variables and instead there was an instance of it for each variable.
Some common uses for the Change () by () block:
- Changing the speed of an object
set [speed v] to (2) set x to (-240) forever change x by (speed) change [speed v] by (1) say [Whee!!!]
- Changing a level number
if (touching [goal v]?) then change [level v] by (1) end
- Changing a value for a math formula
ask [What would you like to add to one?] and wait set [number v] to (answer) say (join[Here it is! ]((1) + (number)))
- Changing the score in a game
if (touching [laser v]?) then change [score v] by (-5) end
- Main article: List of Block Workarounds
This block can be replaced by the following script:
set [variable v] to ((variable) + (amount))
The blank space at the far right contains the number that will change the value—a positive number to increase and a negative number to decrease the variable.