Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 29, 2010 9:28 pm   

Expanding Variables
 
This is something I'm still quite noobish at, and I need some help. The following trigger works perfectly:
Code:

<alias name="spellup" id="1277">
  <value><![CDATA[#LOCAL $_params $_del
$_spellup=1
$_add=0
$_delete=0
$_list=0
$_spells=@_spellup.Arreana
#SWITCH (%begins( "add", %1)) {#IF (%-2!=%null) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_spells {#IF (%ismember( %i, $_params)) {
        #DELI $_params %i
        #ADDI $_del %i
        }}
    #IF (%ismember( "null", $_params)) {#DELNI $_params %ismember( "null", $_params)}
    #FORALL $_params {#IF (%ismember( "null", $_spells)) {#VAR $_spells %replaceitem( %i, 1, $_spells)} {#ADDI $_spells %i}}
    _spellup.Arreana=$_spells
    $_add=1
    $_list=1
    } {#show "You need spells to add."}}
     (%begins( "delete", %1)) {#IF (%-2!=%null && %numitems( $_spells)>0) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_params {#IF (%ismember( %i, $_spells)) {
        #DELI $_spells %i
        #IF (%numitems( $_spells)<1) {#ADDI $_spells "null"}
        } {#ADDI $_del %i}}
    _spellup.Arreana=$_spells
    $_delete=1
    $_list=1   
    } {#IF (%numitems( $_spells)>0) {#show "You need spells to delete."} {#show "Please enter some spells for deletion."}}}
{
  $_spellup=1
  #IF (%params!=%null) {
    $_params=%replace( %params, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #IF (%ismember( @_c_char, "Corszana|Arreana")) {#IF (!@_prayer) {#send "prayer"}}
    #show "Spelling up "@_c_char"..."
    #FORALL $_params {
      #IF (!%ismember( %i, $_spells)) {#send "c '"%i"'"}
      #wait 1000
      }
    #FORALL $_spells {
      #IF (!%ismember( %i, $_params)) {#send "c '"%i"'"}
      #wait 1000
      }
    }
  }
 
  #IF ($_list) {
  #show "Current spellup list:"
  #IF (!%ismember( "null", $_spells)) {#FORALL @_spellup.Arreana {#show %i}} {#show "None found."}
  #IF (%numitems( $_del)>0) {#show %replace( $_del, "|", ", ")" could not be "%if( $_add, "added", "deleted")" because "%if( %numitems( $_del)>1, "they were", "it was")" "%if( $_add, "already", "not")" on the list."}
  }
  #IF (!$_spellup) {#send %cr}]]></value>
</alias>


You need this variable to get it to function:
Code:

 <var name="_spellup" type="Record" id="1276">Yasan=null|Fhaeeus=null|Kerana="armor|stone|shield|bless|frenzy|haste|sanctuary"|Arreana=null|Corda="enhanced recovery|holy presence|armor|bless|frenzy|shield|stone|sanctuary"</var>


Now, if this was only supposed to work on Arreana, it would be perfect. However, every instance of Arreana is variable. If I'm on a different character, it's supposed to see that an adjust likewise. How does it do that? I have a variable named _c_char which records which character I'm on, so all instances of Arreana could be replaced with @_c_char, with the one major problem I'm having is that it's not working. I try replacing:
@_spellup.Arreana with
@{_spellup.@_c_char}

And I get funky errors where the value for the key Arreana is set to 0.Arreana.

My assumption is that I'm not expanding the variables properly, and, if I can learn to do that, then I can get the alias to function fully as intended.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Apr 29, 2010 10:02 pm   
 
Can't do @var.@key, and while @var.$key might work it's generally not a good idea to use a var.var syntax. You will need to use %db():

$_spells = %db(@_spellup,@_c_char)

If you need to do assignment to that @_c_char field, however, you can't use the a=b syntax. For that you will need to use #addkey (keep in mind that unlike #ADDITEM, #ADDKEY completely replaces the prior contents instead of adding to them).

#addkey _spellup @_c_char value
_________________
EDIT: I didn't like my old signature
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 29, 2010 10:18 pm   
 
Thanks Matt, I completely forgot about %db().
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 29, 2010 10:25 pm   
 
Oddly enough, #ADDKEY _spellup @_c_char $_spells isn't working
Code:

<alias name="spellup" id="1277">
  <value><![CDATA[#LOCAL $_params $_del
$_spellup=1
$_add=0
$_delete=0
$_list=0
$_spells=%db(@_spellup, @_c_char)
#SWITCH (%begins( "add", %1)) {#IF (%-2!=%null) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_spells {#IF (%ismember( %i, $_params)) {
        #DELI $_params %i
        #ADDI $_del %i
        }}
    #IF (%ismember( "null", $_params)) {#DELNI $_params %ismember( "null", $_params)}
    #FORALL $_params {#IF (%ismember( "null", $_spells)) {#VAR $_spells %replaceitem( %i, 1, $_spells)} {#ADDI $_spells %i}}
    #ADDKEY _spellup @_c_char $_spells
    $_add=1
    $_list=1
    } {#show "You need spells to add."}}
     (%begins( "delete", %1)) {#IF (%-2!=%null && %numitems( $_spells)>0) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_params {#IF (%ismember( %i, $_spells)) {
        #DELI $_spells %i
        #IF (%numitems( $_spells)<1) {#ADDI $_spells "null"}
        } {#ADDI $_del %i}}
    #ADDKEY _spellup @_c_char $_spells
    $_delete=1
    $_list=1   
    } {#IF (%numitems( $_spells)>0) {#show "You need spells to delete."} {#show "Please enter some spells for deletion."}}}
{
  $_spellup=1
  #IF (%params!=%null) {
    $_params=%replace( %params, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #IF (%ismember( @_c_char, "Corszana|Arreana")) {#IF (!@_prayer) {#send "prayer"}}
    #show "Spelling up "@_c_char"..."
    #FORALL $_params {
      #IF (!%ismember( %i, $_spells)) {#send "c '"%i"'"}
      #wait 1000
      }
    #FORALL $_spells {
      #IF (!%ismember( %i, $_params)) {#send "c '"%i"'"}
      #wait 1000
      }
    }
  }
 
  #IF ($_list) {
  #show "Current spellup list:"
  #IF (!%ismember( "null", $_spells)) {#FORALL %db(@_spellup, @_c_char) {#show %i}} {#show "None found."}
  #IF (%numitems( $_del)>0) {#show %replace( $_del, "|", ", ")" could not be "%if( $_add, "added", "deleted")" because "%if( %numitems( $_del)>1, "they were", "it was")" "%if( $_add, "already", "not")" on the list."}
  }
  #IF (!$_spellup) {#send %cr}]]></value>
</alias>


Using: spellup add Sanctuary

You will see that $_spells = Sanctuary, but, it never updated the _spellup Variable.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Thu Apr 29, 2010 10:34 pm   
 
Testing it a bit, it has something to do with the %replaceitem() I use. For, if the list is already in existence, I can edit it just fine. But if the value of the field is null, then I can't edit it at all.

Edit: And now it works just fine....
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Apr 30, 2010 4:17 am   
 
So, now it's doing it again.... here's the whole class:

Code:

<class name="Spellup Script" id="1278">
  <var name="_spellup" type="Record" id="1276">Yasan=null|Fhaeeus=null|Kerrisacza="armor|stone|shield|bless|frenzy|haste|sanctuary"|Arreana="Enhanced Recovery|Holy Presence|Armor|Shield|Stone|Frenzy|Bless|Sanctuary"|Corszana="enhanced recovery|holy presence|armor|bless|frenzy|shield|stone|sanctuary"</var>
  <alias name="spellup" id="1277">
    <value><![CDATA[#LOCAL $_params $_del
$_spellup=1
$_add=0
$_delete=0
$_list=0
$_spells=%db(@_spellup, @_c_char)
#SWITCH (%begins( "add", %1)) {#IF (%-2!=%null) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_spells {#IF (%ismember( %i, $_params)) {
        #DELI $_params %i
        #ADDI $_del %i
        }}
    #IF (%ismember( "null", $_params)) {#DELNI $_params %ismember( "null", $_params)}
    #FORALL $_params {#IF (%ismember( "null", $_spells)) {#VAR $_spells %replaceitem( %i, 1, $_spells)} {#ADDI $_spells %i}}
    #ADDKEY _spellup @_c_char $_spells
    $_add=1
    $_list=1
    } {#show "You need spells to add."}}
     (%begins( "delete", %1)) {#IF (%-2!=%null && %numitems( $_spells)>0) {
    $_params=%replace( %-2, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    #FORALL $_params {#IF (%ismember( %i, $_spells)) {
        #DELI $_spells %i
        #IF (%numitems( $_spells)<1) {#ADDI $_spells "null"}
        } {#ADDI $_del %i}}
    #ADDKEY _spellup @_c_char $_spells
    $_delete=1
    $_list=1   
    } {#IF (%numitems( $_spells)>0) {#show "You need spells to delete."} {#show "Please enter some spells for deletion."}}}
{
  $_spellup=1
  #IF (%params!=%null) {
    $_params=%replace( %params, ", ", "|")
    $_params=%replace( $_params, ",", "|")
    }
    #IF (%ismember( @_c_char, "Corszana|Arreana")) {#IF (!@_prayer) {#send "prayer"}}
    #show "Spelling up "@_c_char"..."
    #FORALL $_params {
      #IF (!%ismember( %i, $_spells)) {#send "c '"%i"'"}
      #wait 1000
      }
    #FORALL $_spells {
      #IF (!%ismember( %i, $_params)) {#send "c '"%i"'"}
      #wait 1000
      }
  }
 
  #IF ($_list) {
  #show "Current spellup list:"
  #IF (!%ismember( "null", $_spells)) {#FORALL %db(@_spellup, @_c_char) {#show %i}} {#show "None found."}
  #IF (%numitems( $_del)>0) {#show %replace( $_del, "|", ", ")" could not be "%if( $_add, "added", "deleted")" because "%if( %numitems( $_del)>1, "they were", "it was")" "%if( $_add, "already", "not")" on the list."}
  }
  #IF (!$_spellup) {#send %cr}]]></value>
  </alias>
</class>


Done everything I was told to do and it still won't let me use:
spellup add <argument>, at least not when @_c_char is equal to Arreana. This is extremely frustrating.

Edit: Double variables. Ugh.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Fri Apr 30, 2010 2:10 pm   
 
Does that last edit mean that this is solved?
Reply with quote
chamenas
Wizard


Joined: 26 Mar 2008
Posts: 1547

PostPosted: Fri Apr 30, 2010 4:00 pm   
 
Yeah, it somehow formed another variable. I don't know why it does it, but it seems to do these things frequently, even when the variable exists. Oh well. Thanks guys.
_________________
Listen to my Guitar - If you like it, listen to more
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net