Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Miniwindow similar to inventory capture

Miniwindow similar to inventory capture

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Dacrian   Australia  (18 posts)  Bio
Date Mon 01 Feb 2010 10:03 PM (UTC)

Amended on Thu 11 Mar 2010 09:33 PM (UTC) by Dacrian

Message
Edit: See below :)
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #1 on Thu 11 Mar 2010 09:32 PM (UTC)
Message
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%


Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 11 Mar 2010 10:05 PM (UTC)
Message

local line, wildcards, style = wait.match ("*")
  
...

  -- save line in table
  table.insert (inv, styles)


You are getting "style" but saving "styles".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #3 on Thu 11 Mar 2010 11:43 PM (UTC)
Message
Dacrian said:

Can I get the script to ignore any line that says "Queued command: blah"


Just check for that, eg.



-- save line in table
  if not string.match (line, "^Queued command") then
     table.insert (inv, styles)
  end -- if

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #4 on Thu 11 Mar 2010 11:47 PM (UTC)
Message
Nick Gammon said:


local line, wildcards, style = wait.match ("*")
  
...

  -- save line in table
  table.insert (inv, styles)


You are getting "style" but saving "styles".



just goes to show that a new set of eyes spots it. I re-read that code 10 times trying to spot it!!

cheers!
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #5 on Fri 12 Mar 2010 12:48 AM (UTC)
Message
That works beautifully.

Next issue! I can either attempt to wrap the output that I'm collecting (looks a bit tricksy), or create some triggers to capture to variables the amount of each component, eg. just capture the (second) "six" in the line "You count six beeswax candles with a total of six items."

How do I display in the miniwindow defined lines intead of the captured text? eg.
Candles: (variable1)
Torches: (variable2)
Ash: etc


thanks for the help!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #6 on Fri 12 Mar 2010 07:21 PM (UTC)
Message
Just WindowText ... whatever.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #7 on Sat 13 Mar 2010 02:27 AM (UTC)
Message
*facepalm*

what, just like it's written in the script to make the heading?

i'm an eeeeediot!
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #8 on Sun 28 Aug 2011 09:45 AM (UTC)
Message
ok, it's been a while. Ilost this code, so now I'm trying to get it to work again.

running this alias:

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, style)
  -- 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


returns this error:

Error number: 0
Event:        Run-time error
Description:  I:\Program Files\MUSHclient\lua\wait.lua:67: [string "Alias: "]:67: attempt to index global 'style' (a nil value)

stack traceback:

	[C]: in function 'error'

	I:\Program Files\MUSHclient\lua\wait.lua:67: in function <I:\Program Files\MUSHclient\lua\wait.lua:59>
Called by:    Function/Sub: wait.trigger_resume called by trigger

Reason: processing trigger "wait_trigger_178"


here's the output from the MUD:
comps
You open His Mouth.
You count thirty-five beeswax candles with a total of thirty-five items.
You count one cured human right eye with a total of one item.
You count about one bucketful of some fine grey ash inside a pocket in His Mouth with a total of one item.
You count about thirteen handfuls of some purple mineral powder inside the small cardboard box inside a pocket in His Mouth with a total of thirteen items.
You count about one pinch of some white mineral powder inside a pocket in His Mouth with a total of one item.
You count one cured dog heart and five cured human hearts with a total of six items.
You count five lightable torches with a total of five items.
You close His Mouth.
Missed 'You count'
Error raised in trigger function (in wait module)
stack traceback:
        [string "Alias: "]:67: in function <[string "Alias: "]:3>
.
Trigger function "wait.trigger_resume" not found or had a previous error.
Hp: 1593(1593)  Gp: 397(397)  Xp: 261961  Burden: 49%


I have no idea what broke :(
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #9 on Sun 28 Aug 2011 09:52 AM (UTC)
Message

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


Similar to before. You get "styles" but index into "style".

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #10 on Sun 28 Aug 2011 10:00 AM (UTC)
Message
so everywhere that styles appears, i should change it to style? apologies for sounding very dense, I took a 12 month break from MUDding and that was the only time I ever looked at code. Thanks for the fast answer!
Top

Posted by Dacrian   Australia  (18 posts)  Bio
Date Reply #11 on Sun 28 Aug 2011 10:05 AM (UTC)
Message
Did it, worked :)

now just to switch in the WindowText thing and I'm back to where I was

thanks again!

actually, how would I call an alias instead of sending to the MUD side alias? thanks!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


42,412 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.