Define a block
A block defines an in-line function. For example, a block named square multiplies a value by itself and returns the result.
Procedure
-
Start with the
\character. - Optionally add a list of arguments as name:type pairs.
-
Add the
->characters, which mark the beginning of the block’s body. -
Finally, add either a statement list
surrounded by braces:
{and}, or a Gosu expression.
Example
The following block multiplies a number with itself to square the number:
var square = \ x : Integer-> x * x // No need for braces for expressions, but must use for statements
var myResult = square(10) // Call the blockThe value of myResult in this example is 100.
