pssjim 发表于 2013-7-21 06:31:19

[Mushclient]miniwindow的問題

大家好小弟最近剛接觸lua和mush
在mush的官網,有一個是簡單的miniwindow
將身上的物品inventory 掛成一個miniwindow

因為金庸類型mud的maze,可以看到mazemap
圖片http://minus.com/lu2rcJtbgZkhJ

像這張圖一樣

花了很久的時間,發現為什麼miniwindow的顯示有問題
在原始alias裡有一行是local line, wildcards, styles = wait.match ("*")
才發現一直抓不到mazemap的─
導致格式都錯誤


想請問高手,該如何修改這一行呢?


這個簡單的alias
只要修改三個地方就可以簡單顯示你要固定顯示的miniwindow
1.Send "inventory"
2.local x = wait.match ("You are carrying:", 10)
3.if not string.match (line, "^   ") then
看不懂的,我再說明,只希望有高手可以幫忙我,感恩

北大侠客行MUD,中国最好的MUD

hijacker 发表于 2013-7-21 14:12:45

本帖最后由 hijacker 于 2013-7-21 02:18 PM 编辑

-- wait.match: we call this to wait for a trigger (not a regexp)
不知道是不是这个原因,要不要把wait.match换成wait.regexp试试?说真的,几乎无法搞懂楼主的表述。。。yct63.

uniboee 发表于 2013-7-21 15:02:38

看了你的截图,mazemap 的显示中不仅仅有制表符,还有颜色控制符,

这些颜色控制符如果不进行特殊处理,在miniwindow中无法正确显示。

所以应该并不是抓取的问题,而是颜色控制字符如何处理的问题。

pssjim 发表于 2013-7-21 21:57:30

官網原始link
http://www.mushclient.com/forum/bbshowpost.php?id=9965&page=1
抱歉,忘了貼上來

<aliases>
<alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
>
<send>

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)
end -- if

-- request inventory

Send "inventory"


-- wait for inventory to start

local x = wait.match ("You are carrying:", 10)

if not x then
ColourNote ("white", "blue", "No inventory received within 10 seconds")
return
end -- if

local inv = {}
local max_width = WindowTextWidth (win, font, "Inventory")

-- loop until end of inventory

while true do
local line, wildcards, styles = wait.match ("*")

-- see if end of inventory

if not string.match (line, "^   ") then
    break
end -- if

-- save inventory line
table.insert (inv, 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 * (#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, "Inventory", 5, 5, 0, 0, ColourNameToRGB"yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (inv) 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>
页: [1]
查看完整版本: [Mushclient]miniwindow的問題