Page 1 of 1

Initialize and Terminate within a MSR file

Posted: 08 Feb 2013 18:55
by klownboy
Hi Don,
I'm sure MLS and many other things are still keeping you plenty busy, but any chance you might get to the "Initialize" and "Terminate" scripts within a multi-script resource file that we discussed in this thread http://www.xyplorer.com/xyfc/viewtopic. ... ize#p80936. As you explained it, these scripts would be auto-executed when XYplorer detects there presence in the multi-script resource file. I think most XYplorer scriptors would agree, it would be a huge plus for XY scripting.
Thanks,
Ken

Re: Initialize and Terminate within a MSR file

Posted: 08 Feb 2013 20:57
by admin
Next version this will work:

Code: Select all

"_Initialize"
  perm $p_a;
  $p_a = "Hi!";
"A"
  echo "A says: $p_a";
"B"
  echo "B says: $p_a";
"_Terminate"
  unset $p_a;

Re: Initialize and Terminate within a MSR file

Posted: 08 Feb 2013 21:20
by klownboy
Wow! Service with a smile! Well maybe not a smile, but what service. :appl: As users of XY, we're smiling. :)
Thanks Don.
Ken

Re: Initialize and Terminate within a MSR file

Posted: 09 Feb 2013 00:43
by PeterH
What if I add:

Code: Select all

"_C"
  echo "_C says: $p_a";
and Load "Routine", "_C"; ?
Or, if inside script "B" I execute Sub "_C"; ?
I think in both cases (but especially in the latter) "_Initialize" should not be called?

And what's about the order of the routines? May _Initialize and _Terminate both be located at start or end of the file? (I'd prefer to group administrative routines together...)

Re: Initialize and Terminate within a MSR file

Posted: 09 Feb 2013 10:30
by admin
This should answer it:

Code: Select all

"_Initialize"
  // if variable already exists it is NOT reset here but keeps it current value
  perm $p_a;
"_Terminate"
  unset $p_a;

"Show Variable"
  echo $p_a;
"Plus One"
  $p_a = $p_a + 1;
  echo $p_a;
"Minus One"
  $p_a = $p_a - 1;
  echo $p_a;
"Load Plus One"
  // will NOT call "_Initialize"/"_Terminate"
  Load "*", "Plus One";
  // WILL call "_Initialize"/"_Terminate"
  Load "*", "*";
"Sub Plus One"
  // will NOT call "_Initialize"/"_Terminate"
  Sub "Plus One";

Re: Initialize and Terminate within a MSR file

Posted: 09 Feb 2013 13:22
by PeterH
admin wrote:This should answer it:

Code: Select all

...
Aaah - now I understand what I understood wrong :biggrin:
_Initialize is executed only if no label is passed, i.e. when a selection menu is to be shown.
Maybe a problem (in your example): if I Load "Script", "Plus One"; the perm will not be initialized :o
If it's so all code in _Initialize (and _Terminate) should *only* affect the selection menu, not the code of the script itself? (Or again some misunderstanding?)

And a question: in your example _Terminate un-defines $p_a. That is, it is reset. And new initialized on subsequent call, so +1 and -1 will not be additive, but always work on zero value? (Can't test yet :? ) If it's so I think this isn't inteded?

Re: Initialize and Terminate within a MSR file

Posted: 09 Feb 2013 14:15
by klownboy
Hi Don and PeterH,
Asking one of PerterH's questions maybe in a different way... If I call out or load a multi-script resource file (MSR) with a label in a normal left click of a CTB (customized toolbar button) using PeterH's example, Load "Script", "Plus One";, I assume the script will immediately run "Plus One" and not the "_Initilize". Whereas, if I ran the same script without the label from say the right click of a CTB, the "_Initilize" will be run first. I'm not sure if that would be an issue yet or not. I suppose, at least for menus we can always do something different for the left click of a CTB and the right click of the same CTB. We would sense how the CTB is clicked using the "<get trigger>" command in "_Initilize" and then set perm variables based on that before seeing the menus. I would then assume also that "_Terminate" would run, if present, reqardless of whether the multi-script resource file was run without a label or loaded with a specific label and the physical location of "_Initilize and "_Terminate" will not matter.
edit: Sorry, I got that last part wrong based on your example. "_Terminate" will not run, if the MSR file was run with a label. I'm not sure why "_Terminate", if present, couldn't be executed regardless of how the the script was loaded (with or without a label), but that's probably not an issue either.

Thanks,
Ken

Re: Initialize and Terminate within a MSR file

Posted: 09 Feb 2013 16:10
by admin
Let's wait until you got something to test... (soon).

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 04:45
by klownboy
Don, I'm still experimenting, but so far it's working fine for my scripts. Thank you.
Ken

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 12:36
by klownboy
Hi Don, I meant to ask about your example script in the beta thread for "_Initialize", where are you actually setting the variable to a value? Did you leave out the line that sets $p_a to a value? Echo $p_a yields nothing. No problem, I just thought it might confuse someone trying to learn. The line containing, $p_a = "Hi" is in your 08 Feb 1457 post in this thread, but left out on your 09 Feb 04:30 post.
I was away and missed v12.10.0001.
Thanks again,
Ken

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 15:32
by admin
Yes, it maybe would be clearer if I initialized the variable to some value.
But there is this comment:

Code: Select all

// if variable already exists it is NOT reset here but keeps it current value

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 16:10
by klownboy
Actually, I did notice that statement, but I thought in an example, demo or help file, it would be clearer if the variable is initially established...no biggie.

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 16:15
by admin

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 16:49
by binocular222
I tried the beta and found 1 case it doesn't work as expected:

Code: Select all

"_Initialize"
 perm $Hidden;
 $Hidden = "_MenuB"
"MenuA" msg A
"$Hidden" msg B
"MenuC" msg C
MenuB should be hidden as it is preceded by underscore but that menu still shows up (even with an underscore a head)!

Re: Initialize and Terminate within a MSR file

Posted: 10 Feb 2013 17:14
by admin
Confirmed. Fixed in next version.