Page 2 of 2
Re: Initialize/Terminate variables scope
Posted: 17 Feb 2013 20:10
by Marco
admin wrote:OK, this will work now:
...
Awesome, thank you!
Btw, I'll answer to my question above: globals can't be used in captions because they have to be declared as such first. Makes sense.
Re: Initialize/Terminate variables scope
Posted: 17 Feb 2013 20:19
by admin
Yes.
Re: Initialize/Terminate variables scope
Posted: 17 Feb 2013 21:08
by PeterH
Marco wrote:PeterH wrote:So if I define a global in scripts like "_Initialize", "_somename" or "Main" it should function alike. And the same is for assigning values.
From my POV _Initialize is nothing but a script that's automatically executed before label-selection is shown.
Exactly.
Imo, perm should be used for sharing data between different scripts, i.e. scripts coming/belonging to entirely different sources.
Thus, scripts belonging to a MSR should use globals, while scripts coming from different xys files (or different buttons, or catalog items) should rely on perms.
This would explain also my doubts about perms in script captions: shouldn't globals alone suffice?
I'd say no - hope I'm exactly right...
A Global lives from the time it is defined until the current script stack terminates - then it's automatically undefined: looses it's global status and it's value.
A Perm lives from the moment it's first defined (at least) until XY ends. (You *can* also save/restore them.)
This means: global is used to communicate between a group of nested scripts, while perm can communicate between (in sense of nesting) independent scripts.
But perm has one more advantage: as long as a variable is defined as perm it will be trated as such by all references in all future scripts - until undefined (or XY ends). So you have to define a var as perm only once.
This also means the risk of problems is a bit bigger on perm: if a variable is defined perm, and any totally independent script happens to use this name - it uses the perm variable. If a var is "only" defined global and a script uses the same name without defining it global, it will use a local variable and not affect the global.
But as Don said: you should use names for global and perm variables showing their nature - then you will not misuse them by chance.
Re: Initialize/Terminate variables scope
Posted: 18 Feb 2013 02:00
by klownboy
Marco wrote:admin wrote:OK, this will work now:
...
Awesome, thank you!
Btw, I'll answer to my question above: globals can't be used in captions because they have to be declared as such first. Makes sense.
Ah yes, that makes perfect sense. You can't see what isn't there yet. Thanks Marco, PeterH and thanks once again Don.
Ken