ok, so I watched the YouTube tutorial thing (http://gammon.com.au/forum/bbshowpost.php?id=9965). Wonderful! I probably should have done that first! I posted this in that thread, but it hasn't been noticed, I think, so I will delete it and re-post it here.
I used the video (typed out the script as I watched) to create practically the same thing, except I want to capture lines that appear after I send an alias to count a whole bunch of components in a container. I can configure the string match that is stopping the loop to match a certain phrase (eg. You close His Mouth) however I can't get the script to write anything in the miniwindow.
Here's the code I'm using (practically identical to the one in the vid, written above):
require "wait"
wait.make (function() --coroutine starts here
local win = GetPluginID () .. ":inventory"
local font = "f"
if not WindowInfo (win, 1) then
WindowCreate (win, 0, 0, 0, 0, 6, 0, 0)
WindowFont (win, font, "Lucida Console", 9) -- font selection for winiwindow
end -- if
-- request Components
Send "comps"
-- wait for component listing
local x = wait.match ("You open His Mouth.", 10)
if not x then
ColourNote ("white", "blue", "No components list within 10 seconds")
return
end -- if
local inv = {}
local max_width = WindowTextWidth (win, font, "Components")
-- loop until end of components
while true do
local line, wildcards, style = wait.match ("*")
-- see if ended yet
if not string.match (line, "^You count") then
ColourNote ("white", "blue", "Missed 'You count'") -- To notify if something breaks it, eg. no component there
break
end -- if
-- save line in table
table.insert (inv, styles)
-- work out max width needed
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 * (#inv + 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, "Components", 5, 5, 0, 0, ColourNameToRGB "yellow")
--draw each inventory line
local y = font_height * 2 + 5
for i, styles in pairs (inv) do
local x = 5
for _, styles 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
WindowShow (win, true)
end) --end of coroutine
"comps" is the (MUD side) alias that lists the components (I couldn't work out how to call the client side alias called "listcomps" so I just did it this way), however the problem I have is that Discworld MUD echoes back "Queued command: [command]" when you send a whole bunch of commands. So obviously, this was triggering the "if not" end loop. Fixed that by matching the "You close His Mouth." phrase instead of not matching the "You count".
The mini-windows will draw, Components will be written as the heading, except nothing will be written in it.
So I have two problems: Can I get the script to ignore any line that says "Queued command: blah" and how come nothing is getting written in the mini-window?
thanks
D
addition: here's what appears in the output window after "comps" is fired:
comps
You open His Mouth.
You count one cured human left index finger with a total of one item.
You count thirty-five beeswax candles with a total of thirty-five items.
Queued command: count eyes in his mouth
Queued command: count ash in his mouth
Queued command: count powder in box in his mouth
Queued command: count white powder in his mouth
Queued command: count hearts in his mouth
Queued command: count torches in his mouth
Queued command: close his mouth
Queued command: sb
You count four cured human right eyes and four cured human left eyes with a total of eight items.
You count about eight handfuls of some fine grey ash inside a pocket in His Mouth with a total of eight items.
You count about seven handfuls of some purple mineral powder inside the small cardboard box inside a pocket in His Mouth with a total of seven items.
You count about four handfuls of some white mineral powder inside a pocket in His Mouth with a total of four items.
You count four cured human hearts with a total of four items.
Cannot find "torches in his mouth", no match.
You close His Mouth.
Hp: 1593(1593) Gp: 391(391) Xp: 315404 Burden: 44%
|