Initialize and Terminate within a MSR file
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Initialize and Terminate within a MSR file
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
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
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
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;FAQ | XY News RSS | XY X
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Initialize and Terminate within a MSR file
Wow! Service with a smile! Well maybe not a smile, but what service.
As users of XY, we're smiling.
Thanks Don.
Ken
Thanks Don.
Ken
-
PeterH
- Posts: 2829
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Initialize and Terminate within a MSR file
What if I add: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...)
Code: Select all
"_C"
echo "_C says: $p_a";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...)
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
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";
FAQ | XY News RSS | XY X
-
PeterH
- Posts: 2829
- Joined: 21 Nov 2005 20:39
- Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%
Re: Initialize and Terminate within a MSR file
Aaah - now I understand what I understood wrongadmin wrote:This should answer it:
Code: Select all
...
_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
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
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Initialize and Terminate within a MSR file
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
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
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
Let's wait until you got something to test... (soon).
FAQ | XY News RSS | XY X
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Initialize and Terminate within a MSR file
Don, I'm still experimenting, but so far it's working fine for my scripts. Thank you.
Ken
Ken
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Initialize and Terminate within a MSR file
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
I was away and missed v12.10.0001.
Thanks again,
Ken
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
Yes, it maybe would be clearer if I initialized the variable to some value.
But there is this comment:
But there is this comment:
Code: Select all
// if variable already exists it is NOT reset here but keeps it current valueFAQ | XY News RSS | XY X
-
klownboy
- Posts: 4462
- Joined: 28 Feb 2012 19:27
- Location: Windows 11, 25H2 Build 26200.8737 at 100% 2560x1440
Re: Initialize and Terminate within a MSR file
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.
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
Yes. I modified the example: http://www.xyplorer.com/xyfc/viewtopic. ... 368#p82368
FAQ | XY News RSS | XY X
-
binocular222
- Posts: 1423
- Joined: 04 Nov 2008 05:35
- Location: Win11, Win10, 100% Scaling
Re: Initialize and Terminate within a MSR file
I tried the beta and found 1 case it doesn't work as expected:MenuB should be hidden as it is preceded by underscore but that menu still shows up (even with an underscore a head)!
Code: Select all
"_Initialize"
perm $Hidden;
$Hidden = "_MenuB"
"MenuA" msg A
"$Hidden" msg B
"MenuC" msg CI'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
-
admin
- Site Admin
- Posts: 66375
- Joined: 22 May 2004 16:48
- Location: Win8.1, Win10, Win11, all @100%
- Contact:
Re: Initialize and Terminate within a MSR file
Confirmed. Fixed in next version.
FAQ | XY News RSS | XY X
XYplorer Beta Club