2023-01-04 12:45 PM - edited 2023-01-04 12:46 PM
Hello,
So I was reading the reference guide and I'm a bit confused at this part on page 560 :
When resetting the value of a parameter in a certain condition in the Parameter Script using the parameters command, a similar statement must be put into the Master Script. This keeps the object's display correct in cases when the parameter script is not run by the system. E.g.:
! parameter script
if bCondition then
yy = 1
parameters yy = yy
endif
! master script
if bCondition then yy = 1
Mainly what's the point of the parameter script if all the code written in it is effective in master script as well ? Functions like parameters, lock or values work in master script anyway and it being ran first make it seem like double work to use the parameter script. Are there any functions that should strictly be used in parameter script and/or cannot be used in master ?
There is this quote page 546 :
Be sure to put only common calculations here to avoid an unnecessary increase of the evaluation time of the libpart (remember that master script is evaluated before each and every script)
Which means the master script even runs before parameter script so why bother with this script ?
2023-01-05 12:21 PM - last edited on 2023-01-08 07:40 PM by Laszlo Nagy
With the parameters command you can set the values of an "outer"(accessible by users) parameter, but this occurs at the very end of the runtime. Until that the scripts uses the old, not updated value of the parameter which can cause problems. So it is a good practive to create an inner variable with the same name in the master script and in the parameter script you can update the parameter value with this inner variable's value.
Of course you don't have to make this workaround for every parameters, only for those ones which values can be set from scripts, depending on conditions.
I would change that code snippet to something like this however:
! Master script
if bCondition the yy = 1
! Parameter script
if bCondition the parameters yy = yy
2023-01-05 11:03 PM
Thanks for the reply, it makes more sense now.
I do not see many mentions of runtime concepts in the reference guide nor in the GDL Center. Any idea where I can read more about it ?
Also looking for info on scripts I stumbled on this reply by @Peter Baksa in the old message board about an issue I had last time :
https://gdl.Graphisoft.com/forums/topic/variable-mismatch#post-4799
I'm sharing this good quote that may be of interest for others than me
Don’t think about the master script on its own, in fact it is prepended to the actual script that is run. So it doesn’t help with requests that can’t be used in a parameter script.
You can’t control the execution order of the scripts, generally parameter script is run before the 2D/3D.
Something like this:master script -> param script: sets parameters
all variables cleared
master script again with the new parameters -> param script: sets other parameters
all variables cleared
master script again with the new parameters -> 2D script
all variables cleared
master script again with the same new parameters -> 3D script
2023-01-06 04:44 AM
Parameters set in the master script are for real time editing (for my coding)
and parameters to be set at the end of editing are set in the parameter script.
2023-01-06 04:46 AM
for example,
you enlarge a dynamic array in the master script. and they shrink it in the parameter script.
2023-01-06 04:36 PM
Thanks, it's a good way to remember both scripts' roles.
2023-01-06 04:42 PM
Unfortunately I don't know where you can find more about runtime, but what Péter has written down is a good guide 🙂