The MATH block category contains value blocks, comparison blocks, and mathematical operation blocks.
number value
The number value block is a value that is usually placed in or attached to other blocks that are expecting a numeric value. You can type any numeric value into the block. Non-integers (fraction or decimal) will be truncated to integer values.
true/false
The true/false block provides a value of 1 (true) or 0 (false) depending on which is selected.
random true/false
The random true/false block randomly chooses whether to return true (1) or false (0).
random number
The random number block provides a random number between the first inserted low value and the second inserted high value. The first number must be smaller than the second number. If not in that order, the resulting random value may be unexpected, such as a number outside the range specified.
math operation
The math operation block performs a mathematical operation on the two inserted value blocks. Non-integer (fraction or decimal) results will be truncated to an integer. Select one of the following operations from the drop-down menu:
- + addition
- - subtraction
- × multiplication
- ÷ division
- % modulus (remainder after division)
- ^ (raise to the power of)
highest/lowest
The highest/lowest block, when set to highest, provides the highest of the two values placed in the block, and when set to lowest, provides the lowest of the two values placed in the block.
boolean comparison
The boolean comparison block performs a boolean comparison between the two inserted values and provides a 1 (true) or 0 (false) depending on which of the following options is selected:
- and
- or
- and not
- or not
de/increment
The de/increment block increases (increment) or decreases (decrement) the variable attached to it by 1.
not
The not block performs the selected operation on the value attached and provides the result. The options are:
- not: provides the boolean (1/true or 0/false) opposite of the value attached to it. (Any number other than 0 provides a 0/false.)
- negate: provides the signed value complement; for example, negate 9 provides -9).
- abs: provides the absolute value; for example, absolute 9 and absolute -9 both provide 9.)
compare values
The compare values block compares two inserted values and provides a boolean value, 1 if the equation is true, and 0 if it is false. Choose the type of comparison from the dropdown menu:
- = equal to
- ≠ not equal to
- < less than
- ≤ less than or equal to
- > greater than
- ≥ greater than or equal to
constrain value
The constrain value block limits the value of an item to between 0 and 100. Enter the desired minimum (lowest) and maximum (highest) values for an item in the text fields.
advanced math
The advanced math block performs a trigonometric, exponential, or logarithmic function on the inserted values, and stores the result in a variable. Angles are in integer degrees, not radians. Options are:
- the cosine
- the sine
- the tangent
- the square root
- e raised to the power
- the logarithm (base 10)
- the natural logarithm
Since Blockly is working only with integer math, the block requires you to begin with a multiplier (the first inserted value). Although you could use 1 here, larger numbers make this block more precise.
inverse trig
The inverse trig block performs an inverse trigonometric function. The angles that this block calculates and stores are in integer degrees, not radians. Options are:
- arcsine
- arccosine
- arctangent
Because inverse trigonometry operations usually are done on ratios (one number divided by another) this block requires you to input both the numerator and denominator of the ratio. If you need the inverse trig operation of a single number, use 1 as the denominator (the second number).