Procedures & Functions

A procedure in Zoomscript is a statement that can take in zero or more 'parameters' and perform a specific task. A function is a procedure that returns a value, which can be captured for storage in a variable.

Procedures are written in Scratch code, not Zoomscript code. They are defined in packages.

Zoomscript comes with many first-party packages, and also supports third-party packages. These are initialised at startup. Package guides are available on this website that explain the procedures included with Zoomscript.

Procedure calls

Calling procedures is simple. Use the format [procedureName] [param1] ... [paramN] where N = number of parameters. Some procedures have zero parameter imports. All parameters are strings and validation is done through pseudotype checking in the procedure code itself.

Learn about the 'print' function in the io package guide.

Function calls: capturing

As mentioned in the variables tutorial, the returned value of a function can be captured using the ampersand symbol (&). Return values don't have to be captured. Attempting to capture the output of a procedure (no return value) will return null.

You can only capture the return of a function using variables and control structures. Calling functions within another procedure is not supported.

Parameters

When calling a procedure, parameters are tokenized by spaces. You must parse the exact number of parameters required by the procedure you're calling. Space splitting excludes quoted strings and concatenation. The following code is wrong:

Parameters can be:

Parameters cannot be calls to another procedure. Store the returned value in a variable instead.

Pseudotypes are not evaluated, so you must validate input yourself. The compiler can only count how many procedures are being parsed and not whether they are valid. This means you may experience a runtime crash if you parse invalid parameters. For example:

If-statements also support function calls:

Learn more about the 'eq function in the comp package guide. Learn more about the 'random' function in the util package guide.Learn more about the 'print' function in the io package guide.