I'm having the weirdest of issues on Archicad 24 7006 FULL trying to increment a integer value.
So I have this very simple code
if check then test = test + 1 parameters test = test endif
- check is a checkbox
- test is an integer
- I want to increment test every time I check the box
However, when I go to the Parameters list, every time I check the box, the increment is done twice... No matter the value, it will double the increment (if I do test = test + 10, it will increment by 20). So if I want to increment test by 1, I need to do use a dummy Real number, do the increment on dummy and then round_int() it to test.
There is no other code anywhere else. I tested that code alone in Main script and also alone in Parameter script for the same results.
What exactly am I doing wrong ? I've been at it for an hour now and I don't see it 😭 Seems super obvious 😬
Solved! Go to Solution.
All the time that your check box is turned on, it will increment the 'test' parameter every time the script is run.
And as you have discovered the parameter/mater script is run more than once.
So, as Joachim suggests, reset your checkbox to zero (off) once you have incremented the 'test' parameter.
This should solve the issue as he also mentions.
As well as the option in the compatibility options (I think this forces the entire parameter script to only run once - which I have never worked out if it is a good or bad thing, and I don't think it is very well documented anywhere what actually happens - maybe I just haven't looked hard enough), there is also a GDL command ... n = APPLICATION_QUERY ("parameter_script", "firstoccasion_in_progress", isFirstRun)
So you can use the value returned in 'isFirstRun' to determine if it is the first time the script has run.
You can look it up in the GDL reference.
Running parameter script only once might be a matter of taste. It forces writing code that makes the distinction between parameters and variables, so it is more work from start, but will help understanding the code when new features are added to parameters dependent on eachother.
If run only once is not used, checking "firstoccasion_in_progress" can be necessary with GLOB_MODPAR_NAME, because it is always the name of the parameter modified by the user, not the ones modified with the PARAMETERS command.
Just realized that all what you guys said was written in the Reference Guide on page 559 😓
Therefore it makes no sense to increase a parameter value by one in the parameter script since you may not be able to predict the cardinality of executions.
The run of the parameter script is linear, and not necessarily multiple. You can force the parameter script to start only once by checking the Run the parameter script only once option in the object's Compatibility Options panel, if you are sure you don't need it to run many times. This can make objects react faster, saving time and computing resources.
Classic case of RTFM 😅