Global variables in scripting

Please check the FAQ (https://www.xyplorer.com/faq.php) before posting a question...
Muroph
Posts: 561
Joined: 21 Aug 2007 16:13

Re: Global variables in scripting

Post by Muroph »

i'm used to a scripting syntax like this in another app:

Code: Select all

%Name = 1; //global
%name = 1; //local
with all names case-sensitive.

i like to easily distintinguish between local and global variables, so I prefer #2 or #3.
#1 could get really confusing, with variables with the same name being both local and global in the same script.
My shared scripts:
TeraCopy Integration, Tag Manager, Comments Menu, Text Replacer, Image and Media Tools, Checksum Calculator, Video Calculator
only 5 URLs are allowed on the sig...

PeterH
Posts: 2826
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Global variables in scripting

Post by PeterH »

In one thing jacky is very right: even if globals are defined by command you can distinguish local and global vars by name, if using a private naming convention. (And I think, everyone should do this!) But this will often not be as expected, if using scripts of other people. Here a "forced" naming-convention could help a bit.

The other thing is the possible need for the global definition, if not using the prefix-method. I'm used to do this - but would like the possibility to use global vars by just using a prefix...

Maybe all this could be helped by using a "generic" global command, like
global $g_* ;
to request all vars starting with this prefix as global? You could define each single var as global, but also could use the prefixed format.

j_c_hallgren
XY Blog Master
Posts: 5826
Joined: 02 Jan 2006 19:34
Location: So. Chatham MA/Clearwater FL
Contact:

Re: Global variables in scripting

Post by j_c_hallgren »

PeterH wrote:Maybe all this could be helped by using a "generic" global command, like
global $g_* ;
to request all vars starting with this prefix as global? You could define each single var as global, but also could use the prefixed format.
Not sure what I can contribute of value to this discussion, but this possible solution seems reasonable, so that if a user wanted to have their globals as "$_", "$gbl_", "$g_" or whatever prefix makes sense to them, they could.
Still spending WAY TOO much time here! But it's such a pleasure helping XY be a treasure!
(XP on laptop with touchpad and thus NO mouse!) Using latest beta vers when possible.

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

Re: Global variables in scripting

Post by admin »

Thanks for all the input (so far). Finally (after reading books on programming! yep) I decided that the PHP way is great and jacky was right as always. :wink:

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Global variables in scripting

Post by jacky »

admin wrote:Thanks for all the input (so far). I finally (after reading books on programming! yep) I decided that the PHP way is great and jacky was right as always. :wink:
:D The addition of global vars is great, I love it! (and I like the implementation ;))

I have much work to do still, but I already converted one of my scripts and removed lots of getkey/setkey & copytext/<clipboard> and even a few status call I tried putting after copytext's, it all works smoothly and I finally get my status messages perfectly :D Thanks a lot, Sir!

By the way, off topic thoughts :
- Since when does a setkey with empty value removes the key ? I didn't do that at first, and I hadn't realized it did now until I noticed it a few days ago, or did I forgot about it? :roll:
- The key for ² (for me, it's the first one on the second row, i.e. below Esc, above Tab, on the left of the 1) can be mapped from CKS, but when using the window that lists all free shortcuts, it is not on the list, so one can't assign it from UDC
Proud XYplorer Fanatic

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

Re: Global variables in scripting

Post by admin »

jacky wrote:By the way, off topic thoughts :
- Since when does a setkey with empty value removes the key ? I didn't do that at first, and I hadn't realized it did now until I noticed it a few days ago, or did I forgot about it? :roll:
- The key for ² (for me, it's the first one on the second row, i.e. below Esc, above Tab, on the left of the 1) can be mapped from CKS, but when using the window that lists all free shortcuts, it is not on the list, so one can't assign it from UDC
1. Confirmed, and I'm also surprised. But from the code I assume it was always like this. At least I'm not aware of a relevant change here.

2. ² = Ctrl+Alt+2 for me and it's there in CKS and in free shortcuts. The key below Esc here is ^ or ° (Shift), and both are nowhere. :?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Global variables in scripting

Post by jacky »

1. Well, I'm sure it wasn't there at first, and I may have even wished for it (not sure), but I actually still have INI files with lines like "Key=" after I did use setkey with empty values. It wouldn't remove them, but at least "clean" them up with I needed. Anyways, whatever you didn't change was a smart move, I like it like that ;)

2. I have Ctrl+Alt+2 too! ;) Pressing my ² on free shortcuts dialog I get "The key '²' isn't found in the list." And I don't really have a key for your key (it's AltGr+9 or Shift+) to get those for me).
Proud XYplorer Fanatic

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Global variables in scripting

Post by jacky »

FYI, here's what I know :
7.40.0029 leaves an empty Key=
7.50.0005 removes the key
Proud XYplorer Fanatic

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

Re: Global variables in scripting

Post by admin »

jacky wrote:FYI, here's what I know :
7.40.0029 leaves an empty Key=
7.50.0005 removes the key
Ah, yes, got it. Making it short: the current behavior is the standard behavior of the API used to write values to INIs (WritePrivateProfileString). I could go back to the old behavior if there's any use in it... is there?

jacky
XYwiki Master
Posts: 3106
Joined: 23 Aug 2005 22:25
Location: France
Contact:

Re: Global variables in scripting

Post by jacky »

admin wrote:
jacky wrote:FYI, here's what I know :
7.40.0029 leaves an empty Key=
7.50.0005 removes the key
Ah, yes, got it. Making it short: the current behavior is the standard behavior of the API used to write values to INIs (WritePrivateProfileString). I could go back to the old behavior if there's any use in it... is there?
No, I think it's much better that way! In fact,

Code: Select all

setkey "", "", "Section", "file.ini";
will even remove the entire section now, so we can actually do some real cleaning, good stuff :)
Proud XYplorer Fanatic

Post Reply