ATCP demo scripts

Share your scripts and packages with other Mudlet users.
Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: ATCP demo scripts

Post by Ilithyia »

Alright, I called the function from an alias to see what debugging message I would get. I got the following message:

Code: Select all

 object:<ATCP Test> function:<Alias1>
         <[string "status = {}..."]:5: bad argument #1 to 'match' (string expected, got nil)>
So, I think that means that on the 5th line, it was expecting a value to put in the table status for the variable next_level and got nada.

This is the current incarnation of the script I tested:

Code: Select all

status = {}

function CharVitals(event, arg)
      local r = rex.new( "NL:(\\d+)/100 H:(\\d+)/(\\d+) M:(\\d+)/(\\d+) E:(\\d+)/(\\d+) P:(\\d+)/(\\d+) N:(\\d+)/(\\d+) W:(\\d+)/(\\d+)" )
      if r:match(arg) then
         status.next_level,
         status.current_health, status.max_health, 
         status.current_mana, status.max_mana, 
         status.current_ego, status.max_ego, 
         status.current_power, status.max_power, 
         status.current_endurance, status.max_endurance, 
         status.current_willpower, status.max_willpower = r:match( arg )
      end

end
This is what I get from display(atcp):

Code: Select all

table {
  'RoomEnvironment': 'road'
  'CharName': 'Ilithyia Ecclesiar Ilithyia Argentas'
  'RoomExits': 'e,s,u,in'
  'AuthRequest': 'CH dfpnshzbzghjptptgvmh'
  'CharVitals': 'NL:23/100 H:3156/3156 M:4860/4860 E:4632/4176 P:10/10 N:13320/13320 W:22440/22440 '
  'RoomBrief': 'Before the Syrinx Plaza Hotel (road)'
  'RoomFullExits': 'e(17087),s(1559),u(1557),in(10978)'
  'RoomCoordinates': '11,0,-7,0'
  'RoomNum': '1558'
}
Is something wrong with the regex? I'm still confused as to why it worked at all before.

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: ATCP demo scripts

Post by Alexander Divine »

I can see one issue. In your regex matching above, you're using doublebackslahes, i.e. "\\." You're basically telling your client not to look for a number, but instead any instance of "\d", which it's obviously not gonna find.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: ATCP demo scripts

Post by Vadi »

nah, \\d is correct because you'd want lua to give \d+ to regex (otherwise, lua will use the \ for itself)

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: ATCP demo scripts

Post by Ilithyia »

According to the debugger, the problem is with the "if r:match(arg) then" line. It seems that nothing is matching. I don't understand why it wouldn't match? (Especially since it matched successfully before.)

Did anyone else try to run this script? If so, did it work for you guys?

User avatar
Alexander Divine
Posts: 65
Joined: Mon Dec 21, 2009 7:01 pm

Re: ATCP demo scripts

Post by Alexander Divine »

Vadi wrote:nah, \\d is correct because you'd want lua to give \d+ to regex (otherwise, lua will use the \ for itself)
Slapping myself for that one.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: ATCP demo scripts

Post by Vadi »

I don't see a problem. Try r:match(atcp.CharVitals) though

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: ATCP demo scripts

Post by Ilithyia »

That did the trick. Thanks, Vadi.

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: ATCP demo scripts

Post by Ilithyia »

Alright, then. Now I'm back to my original issue before the failure-to-parse fiasco: still not autosipping. I still get this error message from the debugger whenever the function is called through the event handler:

Code: Select all

LUA: ERROR running script ATCP Sipper (ATCP Sipper) ERROR:
However, when I call the function from an alias, the debugger says it's fine.

Code: Select all

LUA OK script ATCP Test (Alias38) ran without errors
It's still parsing fine with each event, so it's something below my echo tests. This is the current incarnation of the script:

Code: Select all

status = {}

function CharVitals(event, arg)
      local r = rex.new( "NL:(\\d+)/100 H:(\\d+)/(\\d+) M:(\\d+)/(\\d+) E:(\\d+)/(\\d+) P:(\\d+)/(\\d+) N:(\\d+)/(\\d+) W:(\\d+)/(\\d+)" )
      if r:match(atcp.CharVitals) then
         status.next_level,
         status.current_health, status.max_health, 
         status.current_mana, status.max_mana, 
         status.current_ego, status.max_ego, 
         status.current_power, status.max_power, 
         status.current_endurance, status.max_endurance, 
         status.current_willpower, status.max_willpower = r:match(atcp.CharVitals)
      end

siphealth = tonumber(status.max_health*0.75)
sipmana = tonumber(status.max_mana*0.75)
sipego = tonumber(status.max_ego*0.75)
berryhealth = tonumber(status.max_health*0.50)
berrymana = tonumber(status.max_mana*0.50)

currenthealth = tonumber(status.current_health)
currentmana = tonumber(status.current_mana)
currentego = tonumber(status.current_ego)

display(status)

echo("\nsiphealth = " .. siphealth)
echo("\nsipmana = " .. sipmana)
echo("\nsipego = " .. sipego)
echo("\nberryhealth = " .. berryhealth)
echo("\nberrymana = " .. berrymana)

echo("\ncurrenthealth = " .. currenthealth)
echo("\ncurrentmana = " .. currentmana)
echo("\ncurrentego = " .. currentego)
echo("\n\nhealbalance = " .. healbalance)
echo("\nberrybalance = " .. berrybalance)

if healbalance == 1 then
      if currenthealth < siphealth then
            send("sip health")
            healbalance = 0.5
      elseif currentmana < sipmana then
            send("sip mana")
            healbalance = 0.5
      elseif currentego < sipego then
            send("sip bromides")
            healbalance = 0.5
      end
end

end
I appreciate all the help guys! I hope I'm not getting bothersome!

User avatar
Heiko
Site Admin
Posts: 1548
Joined: Wed Mar 11, 2009 6:26 pm

Re: ATCP demo scripts

Post by Heiko »

Error messages are not very informative so it's recommended to call the event handler directly to find out more about the error.

Can't look at your script at the moment, but what springs into my eyes is this:
"siphealth = tonumber(status.max_health*0.75)"

This should most likely be: "siphealth = tonumber(status.max_health) * 0.75"
As you cannot do arithmetic operations on a string value, you'll need to convert the string into a number first before doing your calculations.

Ilithyia
Posts: 43
Joined: Wed Mar 10, 2010 11:04 pm

Re: ATCP demo scripts

Post by Ilithyia »

Ok, fixed the tonumber issue. Now the code looks like this:

Code: Select all

status = {}

function CharVitals(event, arg)
      local r = rex.new( "NL:(\\d+)/100 H:(\\d+)/(\\d+) M:(\\d+)/(\\d+) E:(\\d+)/(\\d+) P:(\\d+)/(\\d+) N:(\\d+)/(\\d+) W:(\\d+)/(\\d+)" )
      if r:match(atcp.CharVitals) then
         status.next_level,
         status.current_health, status.max_health, 
         status.current_mana, status.max_mana, 
         status.current_ego, status.max_ego, 
         status.current_power, status.max_power, 
         status.current_endurance, status.max_endurance, 
         status.current_willpower, status.max_willpower = r:match(atcp.CharVitals)
      end

siphealth = tonumber(status.max_health)*0.75
sipmana = tonumber(status.max_mana)*0.75
sipego = tonumber(status.max_ego)*0.75
berryhealth = tonumber(status.max_health)*0.50
berrymana = tonumber(status.max_mana)*0.50

currenthealth = tonumber(status.current_health)
currentmana = tonumber(status.current_mana)
currentego = tonumber(status.current_ego)

display(status)

echo("\nsiphealth = " .. siphealth)
echo("\nsipmana = " .. sipmana)
echo("\nsipego = " .. sipego)
echo("\nberryhealth = " .. berryhealth)
echo("\nberrymana = " .. berrymana)

echo("\ncurrenthealth = " .. currenthealth)
echo("\ncurrentmana = " .. currentmana)
echo("\ncurrentego = " .. currentego)
echo("\n\nhealbalance = " .. healbalance)
echo("\nberrybalance = " .. berrybalance)

if healbalance == 1 then
      if currenthealth < siphealth then
            send("sip health")
            healbalance = 0.5
      elseif currentmana < sipmana then
            send("sip mana")
            healbalance = 0.5
      elseif currentego < sipego then
            send("sip bromides")
            healbalance = 0.5
      end
end

end
Still getting error messages in the debugger everytime the function is called through the event handler. How do you call the event handler directly?

Post Reply