We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2021-02-01 10:59 PM - last edited on 2021-09-14 01:26 PM by Noemi Balogh
Solved! Go to Solution.
2021-02-02 09:03 AM - edited 2022-01-06 12:02 PM
Hi,
The hotspot command takes care of storing the moved hotspots in the parameter list.
You need to write code that adds new entries to the array when amount changes. You probably won't want to overwrite already existing hotspots to 0.
It is possible that amount decreases, but GDL can't decrease the size of arrays, a temporary array has to be created that will be copied back to the parameter.
This has to be done in the parameter script:
if GLOB_MODPAR_NAME = "amount" then ! allow decrease, vardim1 tells stored array size sizetokeep = min(vardim1(spots), amount) ! copy existing hotspots dim newspots[] for i = 1 to sizetokeep newspots[i] = spots[i] next i ! initialize new hotspots, will be skipped when decreasing size for i = sizetokeep + 1 to amount newspots[i] = 0 next i ! store array with new size spots = newspots parameters spots = spots endif
2021-02-02 09:03 AM - edited 2022-01-06 12:02 PM
Hi,
The hotspot command takes care of storing the moved hotspots in the parameter list.
You need to write code that adds new entries to the array when amount changes. You probably won't want to overwrite already existing hotspots to 0.
It is possible that amount decreases, but GDL can't decrease the size of arrays, a temporary array has to be created that will be copied back to the parameter.
This has to be done in the parameter script:
if GLOB_MODPAR_NAME = "amount" then ! allow decrease, vardim1 tells stored array size sizetokeep = min(vardim1(spots), amount) ! copy existing hotspots dim newspots[] for i = 1 to sizetokeep newspots[i] = spots[i] next i ! initialize new hotspots, will be skipped when decreasing size for i = sizetokeep + 1 to amount newspots[i] = 0 next i ! store array with new size spots = newspots parameters spots = spots endif
2021-02-02 10:36 AM
2022-03-23 12:01 PM
I want to know what is the difference, if any, of this:
spots = newspots parameters spots = spots
and this:
parameters spots = newspots
2022-03-23 12:34 PM
There is actually a critical difference.
In the second option the parameter "spots" has to update in the parameter list before the other scripts (2D, 3D) will use the new value.
In the first example the other scripts will respond directly to the "local variable" value set in the master script (spots = newspots) before the parameter value even updates. This makes the object respond dynamically especially in the case of adding new nodes (spots) on the fly in 2D and 3D.
In all my objects I use the first method so that effectively the 2D and 3D are reading values directly from the master script rather than the parameter values. In many cases I don't even have a parameter that relates to the master script local variable.
2022-03-24 03:43 AM
I'm a little confused. (Just started studying GDL.) Does it mean that when I use spots after parameters spots = newspots, the value will be the "old" value and not the values set by parameters statement?
2022-03-24 04:18 AM
Let me try to explain in my non - GDL way (I am not much of a programmer although I get by).
Just saying ... spots = newspots ...
will change the value of the spots variable, but does not actually change the parameter that the user sees.
The new variable value will be used in the scripts - but the users doesn't see it in the interface.
That is why you use ... PARAMETERS spots = spots
This sets the parameter the user sees.
If you just use ... PARAMETERS spots = newspots ...
this will set the parameter the user sees but you have not actually set the value of the variable used in the scripts - yet.
Because of the order the scripts run (they are run multiple times), the new value will not be used in the scripts until the parameter/master script is runs after the new value has been changed.
So although you set the new parameter value, the 2D/3D script might not pick up on it straight away.
So you set the variable value with ... spots = newspots.
And then set the Parameter value with PARAMETERS spots = spots
Barry.
2022-03-31 03:43 PM
The parameters and values commands have a dirty secret: they take effect only after the parameter script ends. So if you just write
parameters spots = newspots
the rest of the parameter script sees the old content of spots, and could update other parameters based on that.
It is not a problem if you never use it again in the parameter script, but its better to keep a habit of writing it correctly.
Another habit could be to only use newspots in the parameter script after that, then the spots parameter needs to be copied at the start of the script when it isn't modified too.