think of mail slots in a large mail room. Your computer has memory that the program is going to use to create and store information. When you create a variable, you are assigning one of the of memory to a name and then can put a value in that slot and modify it as needed. “slots” Why create variables? Variables allow the programmer to make the value modifiable in the script. For example, you want to be able to update a score variable as the player wins/loses in a game. You will see many different uses of variables during this course. You have multiple blocks to create and manipulate variables in the Variables tab palette. button allows you to create a new variable Make a variable button will allow you to delete a button this button only shows – Delete a variable after you have created a variable. will allow you to initialize, or set a beginning value, the variable to a Set [] to (0) value. allows you to modify the value of a variable Change [] by (1) will show the variable and value on the stage. Show variable [] will hide the variable and value on the stage. hide variable [] will allow you to create local variables, more on this use later Script variables (a) To create a variable In the box that pops up - type the name of the variable. The default selection “for all means that all sprites have access to this variable. Select this sprite sprites” “for if you want only the sprite currently selected to be able to access/modify the only” value of the variable. have blocks to use for your variable. Now you’ll Note that you now have a rounded button with the name of the variable in the window with a checkbox to the left. If checked, the variable and value will be show on the stage. Uncheck to hide. When you use one of the variable blocks you will be able to click on the combo box arrow for a list of your variables. Script Variables Sometimes you need a variable in your script, but you want it to step through consecutive don’t integer values as in the for block. A more general way to handle variables uses the block to create a variable, and the block to give that variable a value. Both of these blocks are in the Variables palette. an Here’s
think of mail slots in a large mail room. Your computer has memory that the program is going to use to create and store information. When you create a variable, you are assigning one of the “slots” of memory to a name and then can put a value in that slot and modify it as needed. Why create variables? Variables allow the programmer to make the value modifiable in the script. For example, you want to be able to update a score variable as the player wins/loses in a game. You will see many different uses of variables during this course. You have multiple blocks to create and manipulate variables in the Variables tab palette. Make a variable button allows you to create a new variable Delete a variable button will allow you to delete a button – this button only shows after you have created a variable. Set [] to (0) will allow you to initialize, or set a beginning value, the variable to a value. Change [] by (1) allows you to modify the value of a variable Show variable [] will show the variable and value on the stage. hide variable [] will hide the variable and value on the stage. Script variables (a) will allow you to create local variables, more on this use later To create a variable In the box that pops up - type the name of the variable. The default selection “for all sprites” means that all sprites have access to this variable. Select “for this sprite only” if you want only the sprite currently selected to be able to access/modify the value of the variable. Now you’ll have blocks to use for your variable. Note that you now have a rounded button with the name of the variable in the window with a checkbox to the left. If checked, the variable and value will be show on the stage. Uncheck to hide. When you use one of the variable blocks you will be able to click on the combo box arrow for a list of your variables. Script Variables Sometimes you need a variable in your script, but you don’t want it to step through consecutive integer values as in the for block. A more general way to handle variables uses the block to create a variable, and the block to give that variable a value. Both of these blocks are in the Variables palette. Here’s an