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

Gammon Software Solutions forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Alias not executing properly from prompt trigger when regex is matched.

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Alias not executing properly from prompt trigger when regex is matched.
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Beginner   (6 posts)  [Biography] bio
Date Sat 04 Apr 2009 10:42 PM (UTC)  quote  ]
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!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sat 04 Apr 2009 09:35 PM (UTC)  quote  ]

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

Posted by Beginner   (6 posts)  [Biography] bio
Date Sat 04 Apr 2009 01:04 PM (UTC)  quote  ]
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>
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sat 04 Apr 2009 05:11 AM (UTC)  quote  ]
Message
Can you show exactly what you did please?

See: http://mushclient.com/copying



- Nick Gammon

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

Posted by Beginner   (6 posts)  [Biography] bio
Date Sat 04 Apr 2009 04:42 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Beginner   (6 posts)  [Biography] bio
Date Sat 04 Apr 2009 04:33 AM (UTC)  quote  ]
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!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sat 04 Apr 2009 03:50 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Beginner   (6 posts)  [Biography] bio
Date Sat 04 Apr 2009 12:54 AM (UTC)  quote  ]
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 :)
[Go to top] top

Posted by Onoitsu2   USA  (246 posts)  [Biography] bio
Date Fri 03 Apr 2009 10:38 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Beginner   (6 posts)  [Biography] bio
Date Fri 03 Apr 2009 11:55 AM (UTC)  quote  ]
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-
[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,138 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]