max of (x) and (y)
that reports which of its two inputs is the greater number (the maximum). Load that block now or quickly recreate it.The max
block has an unexpected behavior. It is intended to work only for numbers, yet you can type text into it!
You have already used to check for situations like this. You can also define blocks to show what the expected input type is (number, text, etc.).
max
block. In the editor, click on the input name x
.
move
block was defined always to start as x
and y
to take only numbers and to have the default values of 5 and 10. You will see this in the Block Editor.
x
and y
, even though the block's title line looks different. The # indicates that the input should be a number; the "= 5" shows the default value.When you click OK, your block should look like this . You can no longer type text as input.
When an input type is restricted, a block can still receive improper values. snap doesn’t constantly check to see what types are passed as values. Specifying the input type is an organizational tool to remind you what the domain (input values) of your blocks should be.
If you have a job writing computer programs that do something people rely on, a lot of the effort goes into making sure all your inputs are of the correct type. This can get complicated; maybe the input has to be a positive number; maybe it has to be a positive number that's a multiple of 1/100 (i.e., an amount expressed in dollars, but a whole number of cents). It's not unusual for the error-checking code to be longer than the part of the program that actually does the work. But in this course it's generally okay to ignore possible input errors, as long as your programs work correctly for correct inputs. We want to keep you focused on the interesting parts of the projects.
between
and integer?
to restrict their input values to numbers.