Author Topic: Some Namespace questions...  (Read 2787 times)

0 Members and 1 Guest are viewing this topic.

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Some Namespace questions...
« on: May 12, 2011, 07:27:44 AM »
0
Hey all,

Been working on revamping a lot of my EUO code as I've come a long way and learned many new things and better ways of implementing logic with each script I write. I still have much longer to go though and right now I have a couple of basic questions about Namespaces that I'm hoping someone will be willing and able to clear up for me.

First, is there a reason to use Namespace Clear other than making sure your variables are back to N/A the next time you come around to use the sub? I can see this as a good best practice of course, especially in a sub that could have different %0 values with each call depending on what you are wanting it to do. But is there any memory impact or performance degradation associated with not clearing these that is actually quantifiable?

The other question is functional. I know that we can set the #RESULT sys var to a value that we want to return then perform a "return #RESULT" after "pop'ng" the namespace. How about 2 return values? More? I also understand you can use Namespace Copy to pass variables between namespaces, would this be the right way to do this? It seems a little messy but if that's the only way...

Always appreciate the help guys!

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: Some Namespace questions...
« Reply #1 on: May 12, 2011, 09:15:51 AM »
0
their was a pretty good writeup about the whole namespace thing somewhere around here.. i need to find it and read it myself as i havent been using namespaces and i should be.
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Some Namespace questions...
« Reply #2 on: May 12, 2011, 09:41:39 AM »
0
their was a pretty good writeup about the whole namespace thing somewhere around here.. i need to find it and read it myself as i havent been using namespaces and i should be.
Thx m8 but yep, that's something TM wrote up quite some time ago and, believe me, I've read it ;) Many times over the year/s actually. I just went back through it today in hopes of answering my own questions before posting this discusison.

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Some Namespace questions...
« Reply #3 on: May 26, 2011, 09:45:59 AM »
0
Just a bump on this. I'm still curious how one would return more than a single value from a namespace. Is namespace copy the only real way?

Why not concatinate the results into a single #RESULT with a seperator then break them out to individual variables on the return?

Code: [Select]
gosub givemesomevars

str pos _ #RESULT
set %i #strRes
str left #RESULT %i - 1 ;(can I use the subtraction operator here like this or do I need to set a %tmp var first?)
set %Var1 #strres
str right #RESULT %i + 1 ;(same question as above)
set %Var2 #strres

Display %Var1 , _ , %Var2 ; should equal "Value1_Value2"

sub givemesomevars
   namespace push
   namespace local nsVars
   set !Var1 Value1
   set !Var2 Value2
   set #RESULT !Var1 , _ , !Var2
   namespace clear
   namespace pop
return #RESULT

Is this correct? This seems cleaner than a namespace copy but what do I know? Also, looks reasonable for two return values but seems like it would get complex quickly! 

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

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: Some Namespace questions...
« Reply #4 on: May 26, 2011, 12:04:41 PM »
0
That's really the only way to do it.  I've also returned variables in %1, %2, %3 vars also.  That's not a great idea because any subsequent "gosub" will scramble those, so you need to know what you are doing.

Any time you embed multiple arguments in a "return" value, you have to use STRING functions to split them.  I've found through lots of experimentation that the string functions included in EUO are terribly slow.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Some Namespace questions...
« Reply #5 on: May 26, 2011, 01:09:51 PM »
0
That's really the only way to do it.  I've also returned variables in %1, %2, %3 vars also.  That's not a great idea because any subsequent "gosub" will scramble those, so you need to know what you are doing.

Any time you embed multiple arguments in a "return" value, you have to use STRING functions to split them.  I've found through lots of experimentation that the string functions included in EUO are terribly slow.
Darn, I was afraid of that. So it doesn't sound like something you would want to do as part of often-executed code then... How slow is "slow"?

Thanks for the feedback TM.

X
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

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: Some Namespace questions...
« Reply #6 on: May 26, 2011, 02:03:33 PM »
0
It's not bad if you aren't forming a loop around lots of returned data.  If you are talking Order(1), then whatever, but if you are doing something like this at O(n) or O(n^2), then it'll be a problem.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline 12TimesOverTopic starter

  • Another Day, Another Vendetta
  • Global Moderator
  • *
  • *
  • Posts: 3694
  • Activity:
    0%
  • Reputation Power: 41
  • 12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.12TimesOver is a force to reckon with.
  • Gender: Male
  • Respect: +321
  • Referrals: 2
    • View Profile
Re: Some Namespace questions...
« Reply #7 on: May 26, 2011, 03:39:30 PM »
0
Well that should be fine then, good to know.

Out of curiosity though, are you saying that you can return multiple values on a line as %1, %2, etc ( return value1 value2 value3 )? I didn't think you could do that.
When they come for me I'll be sitting at my desk
     with a gun in my hand wearing a bulletproof vest
My, my, my how the time does fly
     when you know you're gonna die by the end of the night

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: Some Namespace questions...
« Reply #8 on: May 26, 2011, 03:41:41 PM »
0
oh no, not that.  You are just setting them before you hit the return.  For that, you can just call out vars like %rva1, %rval2, etc. 
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: