Page 2 of 2
Re: Global variables in scripting
Posted: 25 Oct 2008 04:11
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.
Re: Global variables in scripting
Posted: 25 Oct 2008 12:37
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.
Re: Global variables in scripting
Posted: 25 Oct 2008 15:55
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.
Re: Global variables in scripting
Posted: 27 Oct 2008 14:41
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.

Re: Global variables in scripting
Posted: 27 Oct 2008 20:19
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.


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

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?

- 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
Re: Global variables in scripting
Posted: 27 Oct 2008 20:35
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?

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

Re: Global variables in scripting
Posted: 27 Oct 2008 20:55
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).
Re: Global variables in scripting
Posted: 27 Oct 2008 21:06
by jacky
FYI, here's what I know :
7.40.0029 leaves an empty Key=
7.50.0005 removes the key
Re: Global variables in scripting
Posted: 27 Oct 2008 21:59
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?
Re: Global variables in scripting
Posted: 27 Oct 2008 22:04
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
