Author Topic: Namespace var interaction  (Read 6610 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
Re: Namespace var interaction
« Reply #15 on: February 26, 2010, 11:54:46 AM »
0
K, I'm still digging in my code but I'm at work so no runnie for me :(

So the following should be true:

Code: [Select]
set !NSVar Hello  ;<----- Set the value of !NSVar to Hello
gosub 1
Halt

sub 1
   namespace push  ;<----- stores !NSVar from #NSNAME=STD
   namespace local 1  ;<----- Value of !NSVar becomes N/A because the value set in the STD Namespace has been stored by the "Push" and a new NS created
   set !NSVar World1  ;<----- Set the value of !NSVar to World1
   gosub 2
   namespace pop  ;<----- Value of !NSVar Becomes Hello because we've "popped" thus the value from STD is restored
return

sub 2
   namespace push  ;<----- stores !NSVar from #NSNAME=1
   namespace local 2  ;<----- Value of !NSVar becomes N/A because the value set in Sub 1 has been stored by the "push" and a new NS created
   set !NSVar World2  ;<----- Set the value of !NSVar = World2
   namespace pop  ;<----- Value of !NSVar becomes World1 because we've "popped" thus the value from Sub 1 is restored
return

If so, I think I've finally got somewhere but I still don't know what in hades is going on with my script yet because everything seems ok.

Lastly, I'm assuming it is a best practice to clear a namespace before pop'ng if those vars aren't necessary for the next iteration just to save memory; would that seam reasonable?

Thanks again.

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

Scrripty

  • Guest
Re: Namespace var interaction
« Reply #16 on: February 26, 2010, 12:30:44 PM »
0
How do you debug your namespaces TM?  There's gotta be an easy way... you said you had something that does it for you once I think...?

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: Namespace var interaction
« Reply #17 on: February 26, 2010, 12:33:51 PM »
0
Clearing the name space is really up to you.  Just like in "C", you might have a "volatile" region of memory that you may want data to persist.  So it's really up to you and whether you want to keep the data.  For me, I end up using namespaces quite a bit like one might use arrays for, so I want that data to persist.  A good example of that is my Advanced Journal Handler.  Each journal scanner you include in your script resides in its own namespace.  That way it keeps its own copy of the #Jindex value and remains separate from the rest of the journal scanners.  But because of that, I never want to "clear" the namespace.

For your example, if you do a display of the data once you call gosub 1, try this:

Code: [Select]
namespace copy NSVar from local 1
set %NSVar1 !NSVar
namespace copy NSVar from local 2
set %NSVar2 !NSVar
display ok %NSvar1 , #SPC , %NSVar2
stop
Please read the ScriptUO site RULES
Come play RIFT with me!

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: Namespace var interaction
« Reply #18 on: February 26, 2010, 12:34:51 PM »
0
How do you debug your namespaces TM?  There's gotta be an easy way... you said you had something that does it for you once I think...?

I have an unreleased namespace debugger I use.  However, you can get a good indication about how badly you are borking up your namespace code by looking at the VARDUMP.  Very useful, even though it's very clunky.
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: Namespace var interaction
« Reply #19 on: February 26, 2010, 12:41:25 PM »
0
Your confusion confuses me.
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 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: Namespace var interaction
« Reply #20 on: February 26, 2010, 04:45:59 PM »
0
Hehe, I manage to confuse myself pretty quickly so I'm sure it's not to hard to confuse others ;)

I do get the Namespace Copy portion and can see why in some cases you wouldn't want to clear namspace vars. The thing I'm troubleshooting is in the miner script. I've made a bunch of logic changes and tried to streamline some funcitons in 2.6 in order to prep for the feature updates in 3.0. Part of this has been to implement my own standardized subs for gumps, clicks, etc. Somewhere in the logic I'm leaving variables set in STD as N/A so I'm thinking, based on all of our discussion, that I must be jumping out of a sub without pop'ng. Unfortunately I can see nothing glaringly obvious.

My logic is somehting like:

Code: [Select]
Set !totinker yes

Find shovel
If #findkind = -1 && !totinker = yes
   gosub Tinker shovel

sub tinker
   do stuff to use tool
   gosub gumpwait gumpname gumpname gumpsize
   gosub click x y
return

sub click
   namespace push
   namespace local Click
   set !clickx %1
   set !clicky %2
   click !clickx !clicky
   gosub gumpwait generic_gump generic_gump 507_123
   namespace pop
return

sub gumpwait
   namespace push
   namespace local GW
   set !GName1 %1
   set !GName2 %2
   set !GSize %3
   wait for stuff
   namespace pop
return

So this is obviously an oversimplified version but it makes the point. I go from the script body with the value of !ToTinker set to Yes. I Push STD and make a new namespace for clicking and gosub to the gumpwait and another push and new namespace GW. I pop/return, then pop/return thus I should be back to the STD namespace with !Totinker being back to a value of Yes but, instead, it stays N/A. This would seem as though I'm not pop'ng correctly out of one of the click or gump subs but I see nothing wrong.

Point is, this is why I'm asking so many questions lol! I'm really learning a lot, just not enough to figure out WTH I'm doing wrong hehe.

At some point I may post the code for debug if I end up giving up.

Any low-level dirt on how a namespace variable gets stored in memory during a namespace push operation?

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

Scrripty

  • Guest
Re: Namespace var interaction
« Reply #21 on: February 26, 2010, 06:37:24 PM »
0
Don't blank namespaces default to STD?  I thought I read that...

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: Namespace var interaction
« Reply #22 on: February 26, 2010, 06:38:55 PM »
0
Don't blank namespaces default to STD?  I thought I read that...

Well, the default to what you left them at last.  Look at #NSNAME to see.  Upon power up, it is STD.
Please read the ScriptUO site RULES
Come play RIFT with me!

Tags: