Page 1 of 2
[Solved] Is this way of declaring variable possible?
Posted: 03 Jan 2013 09:13
by binocular222
I want to declare global variable first then apply to few scripts with captions, for example:
Code: Select all
$var = Sample Variable;
"go to" goto $var;
"copy to" copyto $var
It seems that XYplorer completely ignores the 1st code line above

Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 09:56
by Marco
Does this work as you want?
Code: Select all
$var = Sample Variable;
"go to" goto $var;
"copy to" copyto $var
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 10:01
by Stefan
Vars are script local on default.
That means "to one script only", if you use "Multi-Scripts"
Check the help about "Scripting": "a script resource can have more than one script (multi-script). "
For using Vars at an global scope,
check the "Scripting Commands Reference" for
-- global: Define one or more variables as global.
-- perm: Define one or more variables as permanent.
Read more at >>
http://www.xyplorer.com/xyfc/viewtopic. ... 437#p60437 >> scroll to "Using global variables"
.
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 10:09
by binocular222
I tried decalring global but no use
Code: Select all
global $var;
$var = E:\7Utilities\XYplorer\Scripts\;
"go to" goto $var
"copy to" copyto $var
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 10:28
by admin
Try perm.
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 10:30
by highend
because you have to use the global $var; in every subfunction as well.
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 10:30
by Stefan
binocular222 wrote:I tried decalring global but no use
Code: Select all
global $var;
$var = E:\7Utilities\XYplorer\Scripts\;
"go to" goto $var
"copy to" copyto $var
It is more like:
Code: Select all
global $var;
$var = E:\7Utilities\XYplorer\Scripts\;
"go to"
global $var;
goto $var;
"copy to"
global $var;
copyto $var;
But the script will not work as expected since the first part is not executed automatically.
Depending on what you want to do with your script you have to build it in an other way.
Or we have to do an scripting improving wish to Don:
introduce an kind of auto-run "main" script.
Like:
Code: Select all
"_XYS_MAIN"
global $var;
$var = E:\7Utilities\XYplorer\Scripts\;
"go to"
global $var;
msg "GoTo $var";
"copy to"
global $var;
msg "copyto $var";
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 11:41
by PeterH
@Stefan
Code: Select all
"_XYS_MAIN"
global $var;
$var = E:\7Utilities\XYplorer\Scripts\;
"go to"
load "*", "_XYS_MAIN";
global $var;
msg "GoTo $var";
"copy to"
load "*", "_XYS_MAIN";
global $var;
msg "copyto $var";
should do what you want? (See the added load-statements.)
But it's not what binocular222 wants - as I understand he wants to use a variable in the caption of a script.
In short: this seems not possible to me.
But an untested idea: could you misuse "Windows environment variables" for this? I.e. set an environment variable to what you want, (in a script executed before,) and then refer this variable in a caption?
(This evironment variable would act as a kind of global/general "global variable", being "implicite global"...
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 11:57
by binocular222
- Stefan's code does the trick but having do restate global $var in every subscript is not very elegant
- perm does the trick too but I have to run a separate xys file containing perm before running any other script. Uhm, it work but not in a simple way
- @PeterH: I just want to have global $var in the body of script but if it can be integrated in the caption then it's much better
I may stick to perm as a work around and hope that Don has time for this issue
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 12:30
by Stefan
PeterH wrote:@Stefan
[...]
should do what you want? (See the added load-statements.)
OMG that's great.
(I had needed that more often before)
Thank you for sharing!
to use a variable in the caption of a script.
In short: this seems not possible to me.
Since on first start of the script the vars are not yet set,
i think this is not possible too to use $var in menu caption that way.
Perhaps with tricks like perm() and re-loading the script... before first showing the captions?
That why i think about a kind off auto executing "main" section
which should be executed before showing the caption (meaning "executing the rest of the script")
Code: Select all
XYSMAIN >>>
your settings...
<<< XYSMAIN
rest of the script
...
...
...
.
Re: Is this way of declaring variable possible?
Posted: 03 Jan 2013 18:27
by klownboy
Hey PeterH, that's a nice idea on global variable use. I was asking questions about that a month or so ago. What might enhance this idea is you could combine this technique with the new variable <get trigger> and make some varying options in menus depending on whether you left clicked or right clicked the CTB menu. To use and expand on your example (variable xys):
Code: Select all
"_XYS_MAIN"
global $var;
if (<get trigger> == 1) {
$var = "D:\Graphics\IrfanView" }
if (<get trigger> == 2) {
$var = "D:\Tools\XYplorer" }
"go to"
load "*", "_XYS_MAIN";
global $var;
msg "GoTo $var";
"copy to"
load "*", "_XYS_MAIN";
global $var;
msg "copyto $var";
You would assign the a button to run the script like so, load "D:\Tools\XYplorer\Scripts\variable.xys"; Both the left and right buttons would have the same command asignment but the actions would be different depending on whether you left or right clicked. Very nice...it opens up more possibilities.
Thanks,
Ken
Re: Is this way of declaring variable possible?
Posted: 04 Jan 2013 03:54
by binocular222
Nice!
<get trigger> is amazing but why it's not documented in XYplorer help file?
Re: Is this way of declaring variable possible?
Posted: 04 Jan 2013 10:55
by PeterH
Either it's not official (there are some unofficial functions in XY)
or Don missed to add it

Re: Is this way of declaring variable possible?
Posted: 04 Jan 2013 12:19
by klownboy
Don just recently (Dec 07 2012) added the variable in this thread:
http://www.xyplorer.com/xyfc/viewtopic. ... t=klownboy
+ New variable <get trigger> returns the action that triggered a
script:
echo <get trigger>;
Returned values:
None = 0
LeftClick = 1
RightClick = 2
MiddleClick = 4
Notes:
- The <get trigger> variable is cleared after the script is
processed.
- Currently implemented only for Custom Toolbar Buttons.
It still would be great to come up with a decent way to use a variable in the menu caption though without having to resort to a permanent variable.
Ken
Re: Is this way of declaring variable possible?
Posted: 05 Jan 2013 12:44
by admin
PeterH wrote:Either it's not official (there are some unofficial functions in XY)
or Don missed to add it

It is in the help, under the get() function.