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 ➜ Alias not executing properly from prompt trigger when regex is matched.

Alias not executing properly from prompt trigger when regex is matched.

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


Posted by Beginner   (6 posts)  Bio
Date Fri 03 Apr 2009 11:55 AM (UTC)
Message
Hello all, I'm very new to MUSH and MUDs in general, and I've never programmed, so I'm having a bit of trouble making this basic group of triggers and aliases working properly. Here goes

Trigger:
^(\d+)h, (\d+)m, \d+e, \d+w ([cexkdb@]*)-

Executes:
SetVariable("currenthealth", %1)
SetVariable("currentmana", %2)
Execute("HEAL")
Execute("LIMBS")

Trigger:
^Health:\s+\d{1,4}\s/\s(\d{4})\s{5}Mana:\s+\d{1,4}\s/\s(\d{4})$

Executes:
SetVariable("maxhealth", %1)
SetVariable("maxmana", %2)
SetVariable("siphealth", %1-750)
SetVariable("sipmana", %2-550)
SetVariable("mosshealth", %1-1100)
SetVariable("mossmana", %2-1600)

Alias:
HEAL

Executes:
local currenthealth = GetVariable("currenthealth")
local siphealth = GetVariable("siphealth")
local healbalance = GetVariable("healbalance")
local sipping = GetVariable("sipping")

if healbalance == "1" and sipping == "0" then

if currenthealth < siphealth then

Send("sip health")
SetVariable("sipping", 1)

end

end


Everything seems to work fine and dandy until my health becomes a 3-digit number, i.e. anything 999 and below. At that point it simply stops sipping. I've experimented and checked World Properties -> Variables when my health is below 999 and all the variables are still being set correctly, it's just not sipping. I can sit there and wait until my health, which regenerates slowly over time, goes up to a 1000 and as soon as the first prompt indicating it's a 4-digit number pops I start sipping again. Very odd, and looking at the scripting with my beginner eyes I can't see what's causing it. Any help is greatly appreciated. Thanks!

btw, here's what my prompt looks like with 4 and 3 digits of health respectively:
3877h, 2563m, 18285e, 11715w cexkdb-

865h, 2563m, 18285e, 11715w cexkdb-
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #1 on Fri 03 Apr 2009 10:38 PM (UTC)
Message
Not even sure if this is an issue, but perhaps this trigger

^Health:\s+\d{1,4}\s/\s(\d{4})\s{5}Mana:\s+\d{1,4}\s/\s(\d{4})$

Needs the (\d{4}) to be (\d{1,4}) as it might be getting a 3 digit number yet not checking it as it is looking for a 4 digit. That is the only thing I see at first glance, everything allows for 1-4 digits and that only allows for 4.

-Onoitsu2
Top

Posted by Beginner   (6 posts)  Bio
Date Reply #2 on Sat 04 Apr 2009 12:54 AM (UTC)
Message
Well, I tried it even though I didn't think it would be an issue. That particular capture is my maxhealth, not currenthealth, and it's always 4 digits. Regardless, I tried changing it to {1,4} just to see if it would work, but it didn't.

Thank you anyways :)
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #3 on Sat 04 Apr 2009 03:50 AM (UTC)
Message
Your problem is this line:


if currenthealth < siphealth then


It is a problem because variables retrieved by GetVariable are strings. Thus for example, a test like:


if "900" < "1000" then


This does not give the results you expect. For strings, the left-most character is the most significant (so it compares the 9 to the 1). It therefore thinks that "900" is greater than "1000".

To fix it, change them to numbers, eg. change:


local currenthealth = GetVariable("currenthealth")
local siphealth = GetVariable("siphealth")


to:


local currenthealth = tonumber (GetVariable("currenthealth"))
local siphealth = tonumber  (GetVariable("siphealth"))


Then the compare will work correctly.



- Nick Gammon

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

Posted by Beginner   (6 posts)  Bio
Date Reply #4 on Sat 04 Apr 2009 04:33 AM (UTC)
Message
Oh, that's neat. Thanks for the help, Nick. I think I should probably learn what a string is now, and some of the other intricacies of MUSH.

Thanks!
Top

Posted by Beginner   (6 posts)  Bio
Date Reply #5 on Sat 04 Apr 2009 04:42 AM (UTC)
Message
Ah, sorry, now I'm getting this error message:

Run-time error
World: Achaea
Immediate execution
[string "Alias: "]:9: attempt to compare two function values
stack traceback:
[string "Alias: "]:9: in main chunk
[C]: in function 'Execute'
[string "Trigger: "]:3: in main chunk
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #6 on Sat 04 Apr 2009 05:11 AM (UTC)
Message
Can you show exactly what you did please?

See: http://mushclient.com/copying



- Nick Gammon

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

Posted by Beginner   (6 posts)  Bio
Date Reply #7 on Sat 04 Apr 2009 01:04 PM (UTC)
Message
<aliases>
<alias
match="HEAL"
enabled="y"
group="autosipper"
send_to="12"
sequence="100"
>
<send>local currenthealth = tonumber GetVariable("currenthealth")
local siphealth = tonumber GetVariable("siphealth")
local healbalance = GetVariable("healbalance")
local sipping = GetVariable("sipping")
local stupidity = GetVariable("stupidity")

if healbalance == "1" and sipping == "0" then

if currenthealth &lt; siphealth then

Send("sip health")
SetVariable("sipping", 1)

if stupidity == "1" then

DoAfterSpecial(1, 'Execute("resetsipping")', 12)

end

end

end</send>
</alias>
</aliases>
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #8 on Sat 04 Apr 2009 09:35 PM (UTC)

Amended on Sat 04 Apr 2009 09:36 PM (UTC) by Nick Gammon

Message
You left out some brackets. I had:


local currenthealth = tonumber ( GetVariable("currenthealth") )
local siphealth = tonumber  ( GetVariable("siphealth") )


You have:


local currenthealth = tonumber GetVariable("currenthealth")
local siphealth = tonumber GetVariable("siphealth")


Lua allows multiple statements on a single line, so what you effectively have is:


local currenthealth = tonumber;   GetVariable("currenthealth")
local siphealth = tonumber;   GetVariable("siphealth")


In other words you assigned the function "tonumber" to both currenthealth and siphealth, and then when you compared them, it complained you were comparing functions to each other.

- Nick Gammon

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

Posted by Beginner   (6 posts)  Bio
Date Reply #9 on Sat 04 Apr 2009 10:42 PM (UTC)
Message
Ahhhhh ok. I'm new to scripting, so I'm still unused to dotting my i's and crossing my t's, if you will. It's not habit yet. Thank you, works perfectly now.

Sorry about posting in the wrong forum, by the time I realized it was the wrong forum I figured making a second topic would be pointless. Thanks again!
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.


27,628 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.