Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ (Solved) [Lua] Can't go over if value is more than 999

(Solved) [Lua] Can't go over if value is more than 999

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


Posted by gameshogun   Philippines  (9 posts)  Bio
Date Mon 21 Sep 2015 07:05 PM (UTC)

Amended on Mon 21 Sep 2015 07:08 PM (UTC) by gameshogun

Message
MUSHclient v4.99

Trigger

<triggers>
  <trigger
   enabled="y"
   group="warning"
   ignore_case="y"
   match="^[(?P&lt;ahp&gt;\d+)\/(?P&lt;fhp&gt;\d+) (?P&lt;amana&gt;\d+)\/(?P&lt;fmana&gt;\d+) (?P&lt;amove&gt;\d+)\/(?P&lt;fmove&gt;\d+) (?P&lt;axp&gt;\d+) \|(.*?)$"
   name="status_warning"
   regexp="y"
   script="status_warning"
   sequence="100"
  >
  </trigger>
</triggers>


LUA

function status_warning (name, line, wildcards)
  local ahp = wildcards.ahp
  local axp = wildcards.axp

  if ahp < "200" then
    ColourNote ("white", "red", "WARNING - HEALTH IS LOW!")
  end

  if axp < "500" then
    ColourNote ("white", "red", "CHANGE TO LEVELING EQUIPMENT NOW!!")
  end
end


TEST:

Actual: [120/1500 100/800 100/800 2847 | PET: 100/800hp | Q SU]
wildcards: [ahp/fhp amana/fmana amove/fmove axp | *


What's happening:
If the value is 4 digits and above, the if statement always fail. The maximum I can do in this case, is 999.

So, in the example above:
* if ahp < "200" works fine because ahp = 120
* if axp < "500" fails because axp = 2847, so ColourNote gets printed when it should not.

Is there something I'm missing re: LUA?

Thank you for the assistance.

Confirm my identity: https://yukino.keybase.pub
Read my profile: https://jcsesecuneta.com/profile/
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #1 on Tue 22 Sep 2015 02:27 AM (UTC)
Message
Are you actually converting those variables into numbers at some point? If not you're simply comparing strings and you'll never get the behavior you expect to see.

As demonstrated http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=11249

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 22 Sep 2015 04:09 AM (UTC)
Message
I agree with Meerclar.

Your code should probably be:


function status_warning (name, line, wildcards)
  local ahp = tonumber (wildcards.ahp)
  local axp = tonumber (wildcards.axp)

  if ahp < 200 then
    ColourNote ("white", "red", "WARNING - HEALTH IS LOW!")
  end

  if axp < 500 then
    ColourNote ("white", "red", "CHANGE TO LEVELING EQUIPMENT NOW!!")
  end
end


Strings and numbers compare quite differently. The string "1000" is less than the string "999". (1 is less than 9).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by gameshogun   Philippines  (9 posts)  Bio
Date Reply #3 on Tue 22 Sep 2015 04:36 AM (UTC)
Message
Nick Gammon said:

I agree with Meerclar.

Your code should probably be:


function status_warning (name, line, wildcards)
  local ahp = tonumber (wildcards.ahp)
  local axp = tonumber (wildcards.axp)

  if ahp < 200 then
    ColourNote ("white", "red", "WARNING - HEALTH IS LOW!")
  end

  if axp < 500 then
    ColourNote ("white", "red", "CHANGE TO LEVELING EQUIPMENT NOW!!")
  end
end


Strings and numbers compare quite differently. The string "1000" is less than the string "999". (1 is less than 9).


Ah! That's it, "tonumber". And I thought "123" was the style in Lua.

Must start reading the Lua docs, it's getting interesting.

Thank you very much to both of you! *bow*

Confirm my identity: https://yukino.keybase.pub
Read my profile: https://jcsesecuneta.com/profile/
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.


15,819 views.

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

Go to topic:           Search the forum


[Go to top] top

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