ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: crameep on March 28, 2009, 01:33:58 PM
-
Ok, im using some global namespaces in my script for some simple purposes. My question is after i create the namespace or call the namespace in a sub, do i need to namespace pop at the end of the sub everytime I use it?
-
The answer there is definitely YES. You have to think about the way EasyUO uses the namespaces as a stack. So much so that you have to PUSH/POP your current stack.
I guess the best way to explain this is through an example:
namespace local test
set !testval 1
gosub TestFunction
display ok !testval ; Crap! it's 100!
stop
sub TestFunction
namespace push
namespace local test1
set !testval 100
return
Since this code doesn't "pop" back the previous namespace, you are left inside the "test1" namespace which has a different number for !testval assigned.
I guess here it's good to point out that you should also "pop" back to the namespace you came from even if you have branching logic. I've seen many people trying to use namespaces (including some "good" scripters), but they forget to "pop" back from within an "if" statement. Basically, all execution paths should have a "namespace pop" or more precisely make sure you put the script back into a state that is compatible with the operation before you changed to a different namespace.
-
For the rest of us...
Push means "keep the existing variables in a storage container and use these new ! variables until I pops them".
Pop means "forget all about those ! variables we used since the push, and get those stored variables out of the storage container and put them back into the script"
Anyways, I'm not sure if thats what they mean, but thats how I use em :P
-
Ok, I think I got it, Well, see when I get done I suppose :)
-
I like Orange Flavored Push Pops, usually I get the Flinstone's One.
-
I like Orange Flavored Push Pops, usually I get the Flinstone's One.
Ohhhhh! BrainFREEZE!!