Page 1 of 2
Variables in macros
Posted:
Thu Nov 03, 2016 5:28 pm
by Battwell
What is correct syntax to set something to a var in a macro ?
I want to use an if statement to check a variable to see if a tool should be probed or not
Tried for an hour - given up !
Re: Variables in macros
Posted:
Thu Nov 03, 2016 5:47 pm
by ger21
getcar() and setvar(). But you need to be using version 1.2028
http://www.cncdrive.com/UCCNC/setup_1.2028.exe
Re: Variables in macros
Posted:
Thu Nov 03, 2016 5:51 pm
by Battwell
Ah. I'm on 2026. Maybe Why
Re: Variables in macros
Posted:
Thu Nov 03, 2016 10:43 pm
by cncdrive
In earlier versions you could read and write the ivars array, e.g.
ivars[10] = 1.234;
double myvar = ivars[10];
The new Getvar and Setvar functions doing the same, setting the members of the ivars array which are the variables you can code with the # suffix in g-code.
Re: Variables in macros
Posted:
Fri Nov 04, 2016 11:29 am
by Battwell
thanks- i couldnt find that command documented anywhere.
Re: Variables in macros
Posted:
Fri Nov 04, 2016 2:44 pm
by ger21
Is there a list of vars somewhere, and is there a range that's safe for users to use?
Re: Variables in macros
Posted:
Fri Nov 04, 2016 3:51 pm
by Battwell
ok. couldnt get syntax right for old ivars version so i installed 2028.
full syntax that works is
double myvar=exec. Getvar(1); // for variable #1
then used
if(myvar>0)
{
skip this code
}
which works.
except the macro just seems to stop and end after the }
is there a goto function i can use instead ? if so how to write that please
Re: Variables in macros
Posted:
Fri Nov 04, 2016 4:05 pm
by ger21
I don't understand what you want it to do?
Can you use "else"?
Re: Variables in macros
Posted:
Fri Nov 04, 2016 4:27 pm
by Battwell
it was just to skip my probing section in my m6 macro.
it just doesnt resume after the }
(doesnt run the code after ) i havnt worked out why yet.
maybe adding else will work !
Re: Variables in macros
Posted:
Fri Nov 04, 2016 4:36 pm
by ger21
If you want the code to run if myvar > 0, then your code should all be inside of the }.