wait.regexp confused me

Posted by Stwau on Sun 18 Jan 2015 01:43 AM — 3 posts, 12,731 views.

#0
I'm a newbie for mushclient and have read a lot of article about wait.regexp, but still can not understand it.

I wrote a script, please help me to classify the error.

function status:updateHP()
s_match1 = "^·精血·\s+(\d+)\s+/\s+(\d+)\s+\((\d+)%\)\s+·精力·\s+(\d+)\s+/\s+(\d+)\((\d+)\)";
s_match2 = "^·气血·\s+(\d+)\s+/\s+(\d+)\s+\((\d+)%\)\s+·内力·\s+(\d+)\s+/\s+(\d+)\(\+(\d+)\)";
s_match3 = "^·食物·\s+([\d.-]+)%\s+·潜能·\s+(\d+)\s+/\s+(\d+)";
s_match4 = "^·饮水·\s+([\d.-]+)%\s+·经验·\s+(.*)\s+\(([\d.-]+)%\)";

world.Send("hp");

wait.make(function()
local i;
i = 10;

while (i > 0) do
i = i-1;
local l=wait.regexp(s_match1|s_match2|s_match3|s_match4, 5);

if l==nil then
self:updateHP();
return;
end

if string.find(l,"精血") then
print("function: updateHP - string is matched:"..w[1]);
end -- end of if
end -- end of while

wait.time(5);
end); -- end of wait.make
end -- end of the function: updateHP

Does regexp function only match one pattern at one time? Should I send("hp") before or after regexp function.

When I try this script, it seems that loop dead.
#1
Already solved it.

Thanks.
Australia Forum Administrator #2

 local l=wait.regexp(s_match1|s_match2|s_match3|s_match4, 5);


String concatenation is done with "..".