[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Change variable to N/A if a certain value is met

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

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Xandler   (52 posts)  [Biography] bio
Date Fri 18 Jun 2021 10:40 PM (UTC)

Amended on Fri 18 Jun 2021 11:19 PM (UTC) by Xandler

Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Sat 19 Jun 2021 06:52 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Fiendish   USA  (2,525 posts)  [Biography] bio   Global Moderator
Date Reply #2 on Sun 20 Jun 2021 03:55 PM (UTC)

Amended on Sun 20 Jun 2021 03:56 PM (UTC) by Fiendish

Message
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.

https://github.com/fiendish/aardwolfclientpackage
[Go to top] top

Posted by Xandler   (52 posts)  [Biography] bio
Date Reply #3 on Sun 27 Jun 2021 03:38 AM (UTC)

Amended on Sun 27 Jun 2021 03:45 AM (UTC) by Xandler

Message
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?
[Go to top] top

Posted by Nick Gammon   Australia  (23,016 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Sun 27 Jun 2021 06:23 AM (UTC)

Amended on Sun 27 Jun 2021 06:28 AM (UTC) by Nick Gammon

Message
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")

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,315 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]