AJLogo Triggers, Arguments and Local Variables
This describes the inputs to procedures in AJLogo.
There are three possible 'input groups' to a procudure:
Here is the general form:
mk jj((triggers)(args)(local variables) code code code...)
A trigger is an event driven action, which can be a slider change, button change, or mouse event.
Below is procedure which uses a trigger:
mk demoa((lc0mp) pr hit)
lc0mp stands for Logo Canvas zero - Mouse Pressed
Since there can be several canvases, and the main canvas is lc0, lc0mp is when the mouse is pressed in the main canvas.
Each time the mouse is pressed in the main canvas.......
Using a slider (Sl) as a trigger
First create a Slider:
Then make a procedure which has aa as a trigger:
mk testSl((aa) cs rp 4[fd aa rt 90])
Each time the slider changes, a new square is drawn.
Multiple Trigger example:
Add a second slider:
Next edit the procedure to look like:
mk testSl((aa,bb) cs rp bb[rp 4[fd aa rt 90] rt 5])
Below shows how to pass three arguments to a procedure.
mk demob(()(a,b,c) pr + * a b c)
This example does not have a trigger(s) so the triggers list is empty ().
Next is the argument list (a,b,c)
In this case the three arguments are the default data type double.
This procedure also demonstrates the prefix math notation used by AJLogo.
pr (pr)ints the value calculated by ( a * b ) + c.
Here is an example which uses local variables.
Create the procedure:
mk lvdemo(()()(k) =k 55 pr k)
Then run it:
which results in:
To show that k is 'just' a local variable,
we'll set a global varible (to something else):
then run lvdemo again:
and now print the global (non local) value of k:
|Monday, 15-Oct-2018 13:12:42 UTC|