GDL
About building parametric objects with GDL.
SOLVED!

Issue with incrementing an integer

MetalFingerz
Advocate

Hello,

 

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 😬

1 ACCEPTED SOLUTION

Accepted Solutions
Solution
Joachim Suehlo
Advisor

Try this:

	if check then
		test = test + 1
		parameters test = test
		PARAMETERS check = 0
	endif

This works for me.
Also there is a checkbox "run parameter script always once" in the compatibilty options.

Joachim Suehlo . AC12-27 . MAC OSX 13.5 . WIN11
GDL object creation: b-prisma.de

View solution in original post

5 REPLIES 5
Solution
Joachim Suehlo
Advisor

Try this:

	if check then
		test = test + 1
		parameters test = test
		PARAMETERS check = 0
	endif

This works for me.
Also there is a checkbox "run parameter script always once" in the compatibilty options.

Joachim Suehlo . AC12-27 . MAC OSX 13.5 . WIN11
GDL object creation: b-prisma.de
Barry Kelly
Moderator

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.

 

Barry.

One of the forum moderators.
Versions 6.5 to 27
Dell XPS- i7-6700 @ 3.4Ghz, 16GB ram, GeForce GTX 960 (2GB), Windows 10
Lenovo Thinkpad - i7-1270P 2.20 GHz, 32GB RAM, Nvidia T550, Windows 11

Hi,

 

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.

Péter Baksa
Software Engineer, Library as a Platform
Graphisoft SE, Budapest
MetalFingerz
Advocate

So I ended up doing the solution from Joachim.

I did not have the parameter script ran once though because my inputs were lagging (by a run) and because I'm putting pictures on checkboxes, so them not being checked visually was not an issue.

MetalFingerz
Advocate

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 😅

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!