Once students are comfortable manipulating numerical expressions in Polyup, they can move on to more advanced machines, many of which use Inputs, Variables, and Functions.
Inputs are (usually random) numbers that come down from the top of a stack when you run it. Inputs allow you to manipulate not only numerical expressions but create variable expressions and equations.
Variables can be used to store a value. Variables are most useful when they are used in conjunction with inputs, that is, a random number comes down from the top of the screen, and is then stored into a variable. You can design any function of a variable (eg: 2*x+1) and compute the function on any preset value(s) of x.
But inputs can be used without a variable. Try the machine on the right to see how this works.
To demonstrate inputs, try the machine to the right.
In the first chip, you can drag a 2 and a * to the stack. This will double whatever number comes down from the top of the screen.
Variables can be used to take in an input value and then use it multiple times.
In order to use variables, we have to first set the value of the variable. We do this with variable “set” blocks. The variable pane has both set blocks and use blocks, as shown in the picture to the left. Try set and use blocks in the sandbox environment, provided for you below.
For example, the Polyscript below takes in an input and prints it twice. Do you understand why?
Try playing around with variables in the Sandbox machine to the right. Sandbox mode doesn’t let you use inputs, but you can simulate input(s) by putting some number(s) at the top of the leftmost stack.
One important thing to note: When using multiple inputs and variables, the inputs will be eaten by variable set blocks in the opposite order, such that the topmost set block will eat the bottom-most input, and the bottommost set block will eat the top-most input. This is because of the rules of Polyup—Poly goes down until a square block is seen, then the square block takes in circle blocks.