這是試驗後可以用的
local equipment = {}
local max_width = WindowTextWidth (win, font, "你正在使用的裝備有:")
-- loop until end of equipment
while true do
local line, wildcards, styles = wait.match ("*")
-- see if end of equipment
if not string.match (line, "^\<") then
break
end -- if
-- save equipment line
table.insert (equipment, 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 * (#equipment + 2) + 10
-- make window correct size
WindowCreate (win, 0, 0, window_width, window_height, 8, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
-- heading line
WindowText (win, font, "你正在使用的裝備有:", 5, 5, 0, 0, ColourNameToRGB "yellow")
-- draw each equipment line
local y = font_height * 2 + 5
for i, styles in pairs (equipment) 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 equipment item
WindowShow (win, true)
end) -- end of coroutine