Posted by
| Nick Gammon
Australia (23,131 posts) Bio
Forum Administrator |
Message
| First:
if not string.match (line, "*") then
break
end -- if
This is a Lua pattern, not a wildcard, so it won't work. You want:
if not string.match (line, "^[ 0-9][0-9]") then
break
end -- if
That will match on a digit or a space, followed by a digit (which is what your test data was).
Second:
You didn't skip the line with the hyphens.
Third, you didn't have a timeout on your next wait:
local line, wildcards, styles = wait.match ("*|*")
So that will wait indefinitely for a match on *|*.
So you probably want to just wait for "*" which will be anything, including not the group.
This modified alias worked, but you may want to improve the formatting of the output:
<aliases>
<alias
match="test"
enabled="y"
send_to="12"
sequence="100"
>
<send>require "wait"
wait.make (function () -- coroutine starts here
local win = GetPluginID () .. ":group"
local font = "f"
if not WindowInfo (win, 1) then
WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
WindowFont (win, font, "Lucida Console", 9)
end -- if
-- request group
Send "group"
-- wait for group to start
x = wait.match ("*|*", 10)
if not x then
ColourNote ("white", "blue", "No group received within 10 seconds")
return
end -- if
-- skip the hyphens
x = wait.match ("-----*", 10)
if not x then
ColourNote ("white", "blue", "No hyphens received within 10 seconds")
return
end -- if
local grp = {}
local max_width = WindowTextWidth (win, font, "Group")
-- loop until end of inventory
while true do
line, wildcards, styles = wait.match ("*", 5)
-- see if end of inventory
if not string.match (line, "^[ 0-9][0-9]") then
break
end -- if
-- save group line
table.insert (grp, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth (win, font, line))
end -- while loop
local font_height = WindowFontInfo (win, font, 1)
local window_width = max_width + 10
local window_height = font_height * (#grp + 2) + 10
-- make window correct size
WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText (win, font, "Group", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each inventory line
local y = font_height * 2 + 5
for i, styles in ipairs (grp) do
local x = 5
for _, style in ipairs (styles) do
x = x + WindowText (win, font, style.text, x, y, 0, 0, style.textcolour)
end -- for
y = y + font_height
end -- for each inventory item
WindowShow (win, true)
end) -- end of coroutine</send>
</alias>
</aliases>
![Template:pasting](/images/mushclient_logo_tiny.png) |
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
|
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|