Re: Session Manager [v1.02]
Posted: 17 Feb 2013 15:41
Why not simply sub "_Initialize"; ?
Forum for XYplorer Users and Developers
https://www.xyplorer.com/xyfc/
Yes, FluxTorpedoe may use this standard method in his script, but I will customize for myself. As said, I want to call label externally. [::load Sessionmanager.xys, label] would ignore "_Initialize".PeterH wrote:Why not simply sub "_Initialize"; ?
Code: Select all
"_Initialize"
perm $a, $b;
$a = Itema;
$b = Itemb;
"_Terminate"
unset $a, $b
"Menu1 : Menu1"
msg $a with $bSorry, I don't understandbinocular222 wrote:Yes, FluxTorpedoe may use this standard method in his script, but I will customize for myself. As said, I want to call label externally. [::load Sessionmanager.xys, label] would ignore "_Initialize".PeterH wrote:Why not simply sub "_Initialize"; ?
P.S: Dear FluxTorpedoe , the standard method í:Code: Select all
"_Initialize" perm $a, $b; $a = Itema; $b = Itemb; "_Terminate" unset $a, $b "Menu1 : Menu1" msg $a with $b
Code: Select all
"_Initialize"
perm $a, $b;
$a = Itema;
$b = Itemb;
"_Terminate"
unset $a, $b
"Menu1"
msg $a with $b
Code: Select all
"_Initialize"
global $a, $b;
$a = "Itema";
$b = "Itemb";
"Menu1"
global $a, $b;
msg "$a with $b";Code: Select all
load "Script1", "_Initialize";
load "Script1", "Menu1";In this case you have a second MSR file and in it you are loading "_Initialize" from script1 which would which declares the globals and then loading another label in script1 which successfully uses those global variables without declaring them. So I guess we'd have to do more testing to see what happens when load or sub is used withing the same MSR. I would think that globals would have to be declared in another script within the same MSR as we always have, whereas perms would not. What he is referring to in the above quote is directly loading a script (label) within an MSR script as for example in a left/right click definition for a CTB. In this case "_Initialize" would not be loaded automatically. In your case you called "_Initialize" directly before loading another label.If a script within a MSR is called directly (SCs Sub or Load),
then "_Initialize"/"_Terminate" are NOT called.
maybe. maybe not. I tend to the latter.PeterH wrote:But I think Don still has an error (eye-catcher) here: you may call a MSR with a list of captions, like Load "script", "A;B"; leading to a selection list showing the captions for "A" and "B". I think in these situations _Initialize should be executed - but it isn't.
Sorry - I don't understand.admin wrote:maybe. maybe not. I tend to the latter.PeterH wrote:But I think Don still has an error (eye-catcher) here: you may call a MSR with a list of captions, like Load "script", "A;B"; leading to a selection list showing the captions for "A" and "B". I think in these situations _Initialize should be executed - but it isn't.
Well, that may be true, but I made it clear in at least one post that I did not have have to use "_Initialize", but did so simply to test the new capabilities. You know I'm very new to scripting, but in most cases lately, at least since these new functions came out, I was using "perm" in a menu so both perm and "_Initialize" was necessary.I'm afraid the problem is that you misuse _Initialize a bit?
Have you tested what you're saying? I've ran MLS files both with and without menus and "_Initialize" and "_Terminate" are run in both cases.So if you have scripts "A" and "B" in an MSR, and these might be started with or without specifying an explicit caption, one time _Initialize is executed, the other time it's not.
The reason is that this new logic is made to help on display of the script-captions in the selection menu. And it's not executed if no selection menu is to be shown.
(This can be interpreted positive and negative - for me it's OK.)
Yes, I know I've done that, but in my case I wanted to define Perm variables which got displayed. That is "originally" why Don came up "perm" use in this way along "_Initialize." But use of "_Initialize is not limited to that. It will run, if detected, in any MSR file provided one does not load/call out a specific label.If you want to execute some general preparation, like define perm variables, you can do so in a hidden routine like "_prepare", and call this on start of any script. This may be embedded in the current MSR, (called by sub,) or even be in separate script, called by load (then it may even not be hidden).
The point is you can now use "_Initialize" and reduce or avoid using sub or load label at least to establish initial conditions. As I said above, I haven't ran into any situations yet where "_Initialize" isn't run (except when calling a specific label), but I'll do more testing.- But if _Initialize is used to "prepare" for the real script execution, it should be executed always. But this could be done by explicit "sub" or "load" of some (maybe hidden, or external) script.
Yep, that's why I did it. I needed it myself.klownboy wrote:"GUI way to unset perms" will actually be quite handy especially now-a-days doing all this playing around or should I say "testing" of perms. Thanks!
Code: Select all
"_Initialize"
text "Init";
"_Terminate"
text "Term";
"a" Text "a";
"b" Text "b";
"c" text "c";
"sub" sub "a;c";