Author Topic: Dynamic var creation based on %0 value of a gosub?  (Read 4669 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
Dynamic var creation based on %0 value of a gosub?
« on: January 08, 2009, 07:51:00 AM »
0
Not sure if I'm on the right track here, any thoughts? I want to have a sub that accepts an unknown number of parameters and performs actions based on each parameter then moves on to the next. I think I have it conceptually but I know I'm not quite there.

So the example is something like the following. I want to pass on an unknown number of vendor properties then scan for a vendor matching one of those properties. Would this be easier to do if I passed a string more like "Property1_Property2_Property3" then match this against #property? I'm new at this so bear with me!

Code: [Select]
Gosub Findvendor Blacksmith Weaponsmith Etc

;############################
;Sub FindVendor
;############################
; %1 Vendor property 1
; %2 Vendor property 2
; %3 etc
sub findvendor
   Namespace Push
   Namespace Local XIIxFindVendor
   for %Loop 1 %0
      {
      set %tmp
      set %Property %tmp.%Loop   ;<-----Want %Property = Blacksmith then Weaponsmith then Etc
 
      finditem !VendorTypes G_8
      if #findkind <> -1
         {
         event property #findid
         if %Property in #property
            {
            set %vendor #findid
            ignoreitem reset vendors
            Namespace Clear
            Namespace Pop
            return #true
            }
         }
      }
   ignoreitem reset vendors
   Namespace Clear
   Namespace Pop
return #false

This is also my first attempt at integrating Namespaces as I totally see the value now, especially when trying to develop standardized subs. In this particular case I'm not quite sure how to return the value of %vendor if I Clear and Pop before the return but not sure how else to do that. Do I need to do a Copy first?

XII
« Last Edit: January 08, 2009, 07:54:25 AM by 12TimesOver »
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: Dynamic var creation based on %0 value of a gosub?
« Reply #1 on: January 08, 2009, 11:04:38 AM »
0
Man, you are soooo close!

The first suggestion is that if you are going to use namespaces,  you should go ahead and convert your worker variables to the namespace variables !var.

Second is that you need to search through all the input arguments to the function starting at %1, %2, %3, etc up to how many is in %0.  You can do this by using the !loop variable as an index and then doing this:

Code: [Select]
set !Property % . !Loop   ;<-----Want %Property = Blacksmith then Weaponsmith then Etc

So for your example, !Property will return Blacksmith for %1 and Weaponsmith for %2.  Does this make sense how it's working?  I can explain further if you are confused.

Finally, since you are just returning something, you might as well put your return value in your #RESULT variable.  So you are either returning a #FINDID if successful, or #FALSE if nothing is found.  That way you won't loose the result when you switch back to the home namespace (and also clear the worker namespace like you are doing)

Here's kinda what I'm talking about.

Code: [Select]

;############################
;Sub FindVendor
;############################
; %1 Vendor property 1
; %2 Vendor property 2
; %3 etc
sub findvendor
   Namespace Push
   Namespace Local XIIxFindVendor
   for !Loop 1 %0
      {
      set !tmp
      set !Property % . !Loop   ;<-----Want %Property = Blacksmith then Weaponsmith then Etc
 
      finditem !VendorTypes G_8
      if #findkind <> -1
         {
         event property #findid
         if !Property in #property
            {
            ignoreitem reset vendors
            Namespace Clear
            Namespace Pop
            return #findid
            }
         }
      }
   ignoreitem reset vendors
   Namespace Clear
   Namespace Pop
return #false
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: Dynamic var creation based on %0 value of a gosub?
« Reply #2 on: January 08, 2009, 11:28:43 AM »
0
One other thing I just noticed is that you are going to want to look around at all the vendors, and for that you need to perform an event property on each one found, so you'll want to further tweak this (also it lets you get rid of the ignoreitem)

Code: [Select]
;############################
;Sub FindVendor
;############################
; %1 Vendor property 1
; %2 Vendor property 2
; %3 etc
sub findvendor
   Namespace Push
   Namespace Local XIIxFindVendor
   for !Loop 1 %0
      {
      set !Property % . !Loop   ;<-----Want %Property = Blacksmith then Weaponsmith then Etc
      finditem !VendorTypes G_8
      if #FINDCNT > 0
        {
        for #FINDINDEX 1 #FINDCNT
        {
          event property #findid
          if !Property in #property
            {
            Namespace Clear
            Namespace Pop
            return #findid
            }     
          }
        }
      }
   ignoreitem reset vendors
   Namespace Clear
   Namespace Pop
return #false
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: Dynamic var creation based on %0 value of a gosub?
« Reply #3 on: January 08, 2009, 11:35:22 AM »
0
Quote from: TrailMyx
The first suggestion is that if you are going to use namespaces,  you should go ahead and convert your worker variables to the namespace variables !var.
Ah, ok. I wasn't sure about that.

Quote from: TrailMyx
Second is that you need to search through all the input arguments to the function starting at %1, %2, %3, etc up to how many is in %0.  You can do this by using the !loop variable as an index and then doing this:

Code: [Select]
set !Property % . !Loop   ;<-----Want %Property = Blacksmith then Weaponsmith then Etc

So for your example, !Property will return Blacksmith for %1 and Weaponsmith for %2.  Does this make sense how it's working?  I can explain further if you are confused.
No I think I got it. So really my fault in the loop was simply that I wasn't following the right to left concat. rules on the "array" function in that my result would have been something like %var1, %var2, etc rather than the value of %1, %2, etc?

Quote from: TrailMyx
Finally, since you are just returning something, you might as well put your return value in your #RESULT variable.  So you are either returning a #FINDID if successful, or #FALSE if nothing is found.  That way you won't loose the result when you switch back to the home namespace (and also clear the worker namespace like you are doing)
Got it! I didn't stop to think that the system variables would continue to be valid after the clear of the Namespace! Very cool.

Quote from: TrailMyx
One other thing I just noticed is that you are going to want to look around at all the vendors, and for that you need to perform an event property on each one found, so you'll want to further tweak this (also it lets you get rid of the ignoreitem)
Makes sense. The ignoreitem's are a relic of SM's old script and I wasn't sure about them quite yet. Good to have a different direction!

Thanks a lot for the feedback, I'm obsessing on this thing and have been a little stuck! I know what I'll be working on tonight after the kids head to bed lol.

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: Dynamic var creation based on %0 value of a gosub?
« Reply #4 on: January 09, 2009, 01:32:46 PM »
0
BTW, good to see you starting to use namespaces.  They really are quite useful, but do add a bit of complication when it comes to debugging time.  Just wait until you have to pull your hair out when you forget to "POP" from the worker namespace.  That causes some funky results when the rest of the script was relying on data that's no longer there or at least "hidden".  Just remember to keep an eye on #NSNAME and #NSTYPE to be sure you are working in the namespace you should be working within.
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: Dynamic var creation based on %0 value of a gosub?
« Reply #5 on: January 22, 2009, 09:32:26 AM »
0
Yet another question related to strings and variables, only because I'm not at home and able to test myself.

Is the following accurate:
Code: [Select]
set !goldtypes POF
set !XIIxOptions M_ , !goldtypes ;<---so now is the value of !XIIxOptions "M_POF"?

Or does it need to be:
Code: [Select]
set !goldtypes POF
set !XIIxOptions M , _ , !goldtypes ;<---so now is the value of !XIIxOptions "M_POF"?

Thanks!

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: Dynamic var creation based on %0 value of a gosub?
« Reply #6 on: January 22, 2009, 09:34:05 AM »
0
Either will work, but I would use the first example.  You are just concatenating a string together so you will be left with the same result.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline casca

  • Jr. Member
  • **
  • Posts: 27
  • Activity:
    0%
  • Reputation Power: 0
  • casca has no influence.
  • Respect: +3
  • Referrals: 0
    • View Profile
Re: Dynamic var creation based on %0 value of a gosub?
« Reply #7 on: February 21, 2009, 06:02:42 PM »
0
Either will work, but I would use the first example.  You are just concatenating a string together so you will be left with the same result.

Ah man I love TrailMyx.  For those of you that don't know... he's about the best scripter I've ever seen.  I just learned some stuff in this thread. Thanks again Yoda.

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: Dynamic var creation based on %0 value of a gosub?
« Reply #8 on: February 21, 2009, 06:17:51 PM »
0

Ah man I love TrailMyx.  For those of you that don't know... he's about the best scripter I've ever seen.  I just learned some stuff in this thread. Thanks again Yoda.

Glad that an old thread could help. I wish we had the useful information from UOC; there was all kinds of juicy nuggets of information there too!  It's a shame all that information is gone.

No worries, in time we can get it all back if people ask enough questions.
Please read the ScriptUO site RULES
Come play RIFT with me!

Offline casca

  • Jr. Member
  • **
  • Posts: 27
  • Activity:
    0%
  • Reputation Power: 0
  • casca has no influence.
  • Respect: +3
  • Referrals: 0
    • View Profile
Re: Dynamic var creation based on %0 value of a gosub?
« Reply #9 on: February 21, 2009, 07:55:18 PM »
0

Ah man I love TrailMyx.  For those of you that don't know... he's about the best scripter I've ever seen.  I just learned some stuff in this thread. Thanks again Yoda.

Glad that an old thread could help. I wish we had the useful information from UOC; there was all kinds of juicy nuggets of information there too!  It's a shame all that information is gone.

No worries, in time we can get it all back if people ask enough questions.

Yah that was a promising site, too bad the guy running it was bi-polar.

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: Dynamic var creation based on %0 value of a gosub?
« Reply #10 on: February 22, 2009, 04:42:10 AM »
0
Some of that old information can still be found through the nternet Archive (www.archive.org). Kind of a bear to get through it and it's a little touch and go but believe it or not I have had some moderate luck getting hold of a couple of items I thought were lost forever!
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

Tags: