Author Topic: Namespaces Question  (Read 2936 times)

0 Members and 1 Guest are viewing this topic.

Offline crameepTopic starter

  • Jr. Member
  • **
  • Posts: 50
  • Activity:
    0%
  • Reputation Power: 0
  • crameep has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Namespaces Question
« on: March 28, 2009, 01:33:58 PM »
0
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?

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Namespaces Question
« Reply #1 on: March 28, 2009, 01:42:05 PM »
0
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:

Code: [Select]
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.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline Cerveza

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Namespaces Question
« Reply #2 on: March 28, 2009, 01:47:09 PM »
0
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
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline crameepTopic starter

  • Jr. Member
  • **
  • Posts: 50
  • Activity:
    0%
  • Reputation Power: 0
  • crameep has no influence.
  • Respect: +2
  • Referrals: 1
    • View Profile
Re: Namespaces Question
« Reply #3 on: March 28, 2009, 01:52:23 PM »
0
Ok, I think I got it, Well, see when I get done I suppose :)

Offline Khameleon

  • Script Tester - Team Leader
  • Elite
  • *
  • *
  • Posts: 2574
  • Activity:
    0%
  • Reputation Power: 30
  • Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!Khameleon is a rising star!
  • Gender: Male
  • Respect: +238
  • Referrals: 0
    • View Profile
Re: Namespaces Question
« Reply #4 on: March 28, 2009, 04:47:07 PM »
0
I like Orange Flavored Push Pops, usually I get the Flinstone's One.

Offline TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13302
  • Activity:
    0.2%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Namespaces Question
« Reply #5 on: March 28, 2009, 04:47:57 PM »
0
I like Orange Flavored Push Pops, usually I get the Flinstone's One.

Ohhhhh! BrainFREEZE!!
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: