Change variable to N/A if a certain value is met

Posted by Xandler on Fri 18 Jun 2021 10:40 PM — 5 posts, 20,031 views.

#0
I'm working on something on the mud I play on, it's basically something to ID items, long story short, I basically want it so if the required field is empty it changes the value to N/A (since it's not applicable) or 0, I'll post a short example


Can affect you as:
   Affects: DAMROLL By 90
   Affects: STR By 1
   Affects: INT By 5
   Affects: WIS By 4


In the alias I have it as:


if GetVariable("ItemType") == "WEAPON" then
Send ("say Object: @itemname, Item type: @itemtype, Price: @itemprice, Damage Dice: @ItemDDice, Item is: @Itematts, Damage Type: @ItemTypeDam, Affects DAMROLL By @Itemdam, Affects HITROLL By @Itemhit, Affects STR By @Itemstr, Affects WIS By @Itemwis, Affects INT by @Itemint, Affects SPI by @Itemspi")
end


This particular item is a weapon type (hence that check). Since it doesn't meet certain values (ie, this particular item has no hitroll), I would like to change the @ItemHit variable to N/A or 0 then it shows up as such when I call it. I've tried it with ifchecks

if GetVariable("itemhit") == "" then 
SetVariable("itemhit", "N/A")
end

It will change the variable to N/A, but when I call the alias it leaves it blank (like the variable is empty). Is there something obvious I'm missing to fix this?
Amended on Fri 18 Jun 2021 11:19 PM by Xandler
Australia Forum Administrator #1
Unfortunately, you have just given us snippets of what the problem is. To answer I would have to be able to reproduce your problem myself. So, I would need your exact alias for one thing.

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


And I would need to see the events that led to all those variables being set, ie. the MUD output. Without that, it is just guesswork.
USA Global Moderator #2
Nick is right. Next time please include the entire alias structure, not just some bits and pieces.

One and a half issues that I see:

First, you use different capitalization between "@Itemhit" and "itemhit". That's not allowed. The script is case sensitive. You can't just willy nilly change case and expect it to work.

And the half, be careful using "@" expansion notation for MUSHclient variables. Those all get replaced by the values when the alias is invoked, so if you change the value inside the alias it will have the old value instead of the new one until the next time the alias runs.
Amended on Sun 20 Jun 2021 03:56 PM by Fiendish
#3
Right now the exact alias is as follows (I took out the stuff to set it as N/A or 0 as I couldn't figure it out.)


<aliases>
  <alias
   match="ItemID"
   enabled="y"
   expand_variables="y"
   group="Item_id"
   send_to="12"
   ignore_case="y"
   sequence="100"
  >
  <send>if GetVariable("ItemType") == "WEAPON" then
Send ("say Object: @itemname, Item type: @itemtype, Price: @itemprice, Damage Dice: @ItemDDice, Weapon Damage: @Itemdamage, Item is: @Itematts, Damage Type: @ItemTypeDam, Affects DAMROLL By @Itemdam, Affects HITROLL By @Itemhit, Affects STR By @Itemstr, Affects WIS By @Itemwis, Affects INT by @Itemint, Affects SPI by @Itemspi")
end</send>
  </alias>
</aliases>


What it produces is as follows:


You say, 'Object: Blade of Despair, Item type: WEAPON, Price: 0, Damage Dice: 403D403, Weapon Damage: 81406.0, Item is: GLOW BOUND Level-50000 , Damage Type: Slash, Affects DAMROLL By 90, Affects HITROLL By , Affects STR By 1, Affects WIS By 4, Affects INT by 5, Affects SPI by '


from this item:


Object 'Blade of Despair', Item type: WEAPON
Item is: GLOW BOUND Level-50000 
Price: 0
Damage Dice is '403D403' for an average per-round damage of 81406.0.
Damage Type: Slash
Can affect you as:
   Affects: DAMROLL By 90
   Affects: STR By 1
   Affects: INT By 5
   Affects: WIS By 4


Basically, I'd like it to set the stats that aren't in the item to N/A or 0 (that would be hitroll and spi in this case). Also any other items that have stats that don't appear in the identify to register as such.

Also, I have the type defined as there is different types of items in the game such as weapon (what's being used), armor, light, other, etc.

Does this explanation help at all?
Amended on Sun 27 Jun 2021 03:45 AM by Xandler
Australia Forum Administrator #4
GetVariable returns nil if that variable is not defined, so you could do something like this:


Send ("say Object: @itemname, Item type: @itemtype, Price: @itemprice, Damage Dice: @ItemDDice,",
      " Weapon Damage: @Itemdamage, Item is: @Itematts, Damage Type: @ItemTypeDam",
      ", Affects DAMROLL By ", GetVariable ('Itemdam') or "N/A",
      ", Affects HITROLL By ", GetVariable ('Itemhit') or "N/A",
      ", Affects STR By "    , GetVariable ('Itemstr') or "N/A",
      ", Affects WIS By "    , GetVariable ('Itemwis') or "N/A",
      ", Affects INT By "    , GetVariable ('Itemint') or "N/A",
      ", Affects SPI By "    , GetVariable ('Itemspi') or "N/A")