Mudlet Momentum Tracker

by Janalon

Back to Mechanic's Corner.

Janalon2009-08-18 17:11:13
First, a trigger to track the prompt. The pattern is checked via perl regex pattern:

CODE
^(\\d+)h, (\\d+)m, (\\d+)e, (\\d+)p, (\\d+)en, (\\d+)w(, (\\d+)mo)? (\\w+)


Secondly, I use the following in response:

CODE
currenthealth=matches
currentmana=matches
currentego=matches
currentpower=matches
currentendurance=matches
   if matches ~= nil then momentum=matches
      else momentum=0 end
pstats=matches
   if string.find(matches, "e") then bals.equilibrium=1
      else bals.equilibrium=0 end
   if string.find(matches, "x") then bals.balance=1
      else balsbalance=0 end
   if string.find(matches, "p") then bals.proned=1
      else bals.proned=0 end
   if string.find(matches, "l") then bals.larm=1
      else bals.larm=0 end
   if string.find(matches, "r") then bals.rarm=1
      else bals.rarm=0 end


Secondly, I have an alias to pick a kata chain based on my current level of momentum. Check my hunting script where ^pp$ (which I think of punch punch) is set to the following:

CODE
if momentum == 0 then
    send("kata perform " .. pvetar .. " hunt1 hunt1 hunt2 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 1 then
    send("kata perform " .. pvetar .. " hunt1 hunt2 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 2 then
    send("kata perform " .. pvetar .. " hunt2 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 3 then
    send("kata perform " .. pvetar .. " hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 4 then
    send("kata perform " .. pvetar .. " hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 5 then
    send("kata perform " .. pvetar .. " hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
elseif momentum == 6 then
    send("kata perform " .. pvetar .. " hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")
end


Now, when I enter "pp" nothing happens. Not even the kata error message. This would tell me the script is failing because momentum is not properly defined in the tigger, or not referenced correctly. Just to cover all bases, I did check to make sure pvetar was properly defined. The following works:

CODE
send ("kata perform " .. pvetar .. " hunt1 hunt1 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3 hunt3")


I did ask on the Mudlet forum to get this setup, but wanted to check back here. Any recommendations how to fix?
Unknown2009-08-18 17:59:07
I'd try printing momentum and type(momentum) to make sure your equivalence operators are doing their jobs.

Also, you can use "momentum = matches or 0" as Lua shorthand for assigning a value with a default option.
Ilyarin2009-08-18 18:53:11
That's because you're capturing it wrong. Here is an example of what you're catching. You need to use (?:, (\\d)mo)? instead of what you have at the moment. ?: meaning not to store the value of the brackets.

7056h, 6188m, 7329e, 10p, 29690en, 25068w, 5mo elrxkdb

matches = 7056
matches = 6188
matches = 7329
matches = 10
matches = 29690
matches = 25068
matches = , 5mo
matches = 5
matches = elrxkdb
Janalon2009-08-18 20:13:47
Thank you. I'll give that a try. Now, what changes would I have to make to the following:

CODE
currenthealth=matches
currentmana=matches
currentego=matches
currentpower=matches
currentendurance=matches
   if matches ~= nil then momentum=matches
      else momentum=0 end
pstats=matches
   if string.find(matches, "e") then bals.equilibrium=1
      else bals.equilibrium=0 end
   if string.find(matches, "x") then bals.balance=1
      else balsbalance=0 end
   if string.find(matches, "p") then bals.proned=1
      else bals.proned=0 end
   if string.find(matches, "l") then bals.larm=1
      else bals.larm=0 end
   if string.find(matches, "r") then bals.rarm=1
      else bals.rarm=0 end


Would I simply change

CODE
   if matches ~= nil then momentum=matches
      else momentum=0 end


to

CODE
   if matches ~= nil then momentum=matches
      else momentum=0 end
Ilyarin2009-08-18 20:29:07
Assuming you change the part of the prompt trigger to '(?:, (\\d)mo)?', you can leave the code unchanged.
Unknown2009-08-18 21:27:14
When you originally asked on the mudlet forum, I just forgot to put the ?: there. I explained what it did afterwards >.> but forgot to actually put it in the pattern.

To answer your question though, if you did not change the pattern, then yes you could use matches instead and it would work. You're better off changing the pattern though, just because it's a good habit that makes the script more readable.

Just one question though: you are declaring all of those variables first, right? That is, in a script object somewhere, you are doing "momentum=0" to create the variable initially?

Unknown2009-08-18 22:13:31
You don't have to create the variable elsewhere before you initialize it here, so long as any scripts that use the variables either run after this has a chance to set the variables or you take into account the situation where they may not be initialized yet. The kata perform logic would work even if the momentum variable was not initialized beforehand, since it is just doing explicit equivalence comparisons.
Unknown2009-08-18 22:37:36
Good to know, thanks.
Rybosh2009-08-24 08:59:11
QUOTE (Ilyarin @ Aug 19 2009, 04:53 AM) <{POST_SNAPBACK}>
That's because you're capturing it wrong. Here is an example of what you're catching. You need to use (?:, (\\d)mo)? instead of what you have at the moment. ?: meaning not to store the value of the brackets.

7056h, 6188m, 7329e, 10p, 29690en, 25068w, 5mo elrxkdb

matches = 7056
matches = 6188
matches = 7329
matches = 10
matches = 29690
matches = 25068
matches = , 5mo
matches = 5
matches = elrxkdb


Not quite correct.

matches = 7056h, 6188m, 7329e, 10p, 29690en, 25068w, 5mo elrxkdb
matches = 7056
matches = 6188
matches = 7329
matches = 10
matches = 29690
matches = 25068
matches = , 5mo
matches = 5
matches = elrxkdb