Single commands can be entered in the terminal on the bottom of the app screen. All commands, including control structures, can be run within the code block on the left.
Example of what that looks like:
print 5
>5
You said to 'print 5' so it printed the number 5.
More complex sets of commands can be placed in the code editor. All commands must be contained in a named function, also refered to as a "word"; these are defined as the commands between to <function-name>
and end
.
All defined functions can be run in the terminal. Programs can also start with the "go" word, which is triggered by a button on the top left of the interface. 'to' and 'end' will not be recognized by the terminal, which is fundamentally different in that it's meant to run single commands.
to hello-world
print "HelloWorld
end
With the above entered in the code editor, you can enter hello-world
in the terminal and it will run, printing "HelloWorld".
You can also define functions to take arguments:
to hello-user :user
print 'Hello ' + :user
end
Now, if you type hello-user "Maria
you'll see "Hello Maria" printed to the terminal. Functions can take any number of arguments. Thanks to dynamic scope, any arguments will automatically be passed to functions called from the parent function:
to print-value :value
handle-print
end
to handle-print
print :value
end
Entering print-value 5
will print 5. This applies to strings as well.
The computer is able to process commands extremely fast so the "wait" command is used to observe change and analyze data as the program is running. Wait takes a single number value that represents the time to wait in deciseconds(10 deciseconds == 1 second).
to HoldOn
print "starting
wait 10
print "ending
end
If you require more precise wait timing another option is using the mwait command. mwait functions similarly to wait but the value given to it should be in milliseconds(1000 milliseconds == 1 second).
to HoldOnMilli
print "starting
mwait 1000
print "ending
end
Both HoldOn and HoldOnMilli from above should wait the same amount of time between "starting" and "ending" being displayed.