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

Gammon Forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  (Solved) [Lua] Can't go over if value is more than 999
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

(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] Refresh page


Posted by gameshogun   Philippines  (9 posts)  [Biography] 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/
[Go to top] top

Posted by Meerclar   USA  (733 posts)  [Biography] 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
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by gameshogun   Philippines  (9 posts)  [Biography] 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/
[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.


2,367 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 FutureQuest]