AJLogo Triggers, Arguments and Local Variables



This describes the inputs to procedures in AJLogo.
Cheers,
Arnie
 
There are three possible 'input groups' to a procudure:
Here is the general form:
mk jj((triggers)(args)(local variables) code code code...)

Triggers


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.......
hit
hit
hit

Using a slider (Sl) as a trigger
First create a Slider:
aSl aa
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:
aSl bb
Next edit the procedure to look like:
mk testSl((aa,bb) cs rp bb[rp 4[fd aa rt 90] rt 5])

Arguments


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.

Local Variables


Here is an example which uses local variables.
Create the procedure:
mk lvdemo(()()(k) =k 55 pr k)
Then run it:
lvdemo
which results in:
55
To show that k is 'just' a local variable,
we'll set a global varible (to something else):
=k 99
pr k
99
then run lvdemo again:
lvdemo
55
and now print the global (non local) value of k:
pr k
99

           
Monday, 15-Oct-2018 13:12:42 UTC