These two developments have a little but very useful side-effect: we can use static variables after the #Events tag. These variables store their values until the macro is recompiled or UCCNC exits. A small example:
- Code: Select all
AS3.Additemtolistbeginning("Value: " + value, 2);
++value;
#Events
static int value = 0;
Running this macro more times you can see in the status window the increasing value.
Now we have unlimited possibilities. Let's make a tri-state button: every press executes the next function in cycle:
- Code: Select all
switch (state)
{
case 1:
AS3.Additemtolistbeginning("First state", 2);
++state;
break;
case 2:
AS3.Additemtolistbeginning("Second state", 2);
++state;
break;
case 3:
AS3.Additemtolistbeginning("Third state", 2);
state = 1;
break;
}
#Events
static int state = 1;
In the past you had to use #variables or - as the worst way - you could write values to the profile and read back. The first was only for numeric values and could interfere with the running g-code, the second is slow and messes up the profile file.