[Solved] Is this way of declaring variable possible?

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

[Solved] Is this way of declaring variable possible?

Post 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 :?
Last edited by binocular222 on 07 Jan 2013 10:32, edited 1 time in total.
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

Marco
Posts: 2347
Joined: 27 Jun 2011 15:20

Re: Is this way of declaring variable possible?

Post by Marco »

Does this work as you want?

Code: Select all

 $var = Sample Variable;
 "go to" goto $var;
 "copy to" copyto $var
Tag Backup - SimpleUpdater - XYplorer Messenger - The Unofficial XYplorer Archive - Everything in XYplorer
Don sees all [cit. from viewtopic.php?p=124094#p124094]

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Is this way of declaring variable possible?

Post 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"

.

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Is this way of declaring variable possible?

Post 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
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Is this way of declaring variable possible?

Post by admin »

Try perm.

highend
Posts: 13317
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Is this way of declaring variable possible?

Post by highend »

because you have to use the global $var; in every subfunction as well.
One of my scripts helped you out? Please donate via Paypal

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Is this way of declaring variable possible?

Post 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";

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Is this way of declaring variable possible?

Post 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"...
Win11 Pro 223H2 Gerrman

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Is this way of declaring variable possible?

Post 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
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

Stefan
Posts: 1360
Joined: 18 Nov 2008 21:47
Location: Europe

Re: Is this way of declaring variable possible?

Post 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
...
...
...
.

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Is this way of declaring variable possible?

Post 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
Last edited by klownboy on 04 Jan 2013 14:26, edited 1 time in total.
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

binocular222
Posts: 1416
Joined: 04 Nov 2008 05:35
Location: Hanoi, Vietnam

Re: Is this way of declaring variable possible?

Post by binocular222 »

Nice!
<get trigger> is amazing but why it's not documented in XYplorer help file?
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488

PeterH
Posts: 2785
Joined: 21 Nov 2005 20:39
Location: Germany

Re: Is this way of declaring variable possible?

Post by PeterH »

Either it's not official (there are some unofficial functions in XY)
or Don missed to add it :roll:
Win11 Pro 223H2 Gerrman

klownboy
Posts: 4140
Joined: 28 Feb 2012 19:27

Re: Is this way of declaring variable possible?

Post 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
Windows 11, 23H2 Build 22631.3447 at 100% 2560x1440

admin
Site Admin
Posts: 60567
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Is this way of declaring variable possible?

Post by admin »

PeterH wrote:Either it's not official (there are some unofficial functions in XY)
or Don missed to add it :roll:
It is in the help, under the get() function.

Post Reply