[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  Miniwindow similar to inventory capture

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Miniwindow similar to inventory capture
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Sun 28 Aug 2011 10:05 AM (UTC)  quote  ]
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!
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Sun 28 Aug 2011 10:00 AM (UTC)  quote  ]
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!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Sun 28 Aug 2011 09:52 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Sun 28 Aug 2011 09:45 AM (UTC)  quote  ]
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 :(
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Sat 13 Mar 2010 02:27 AM (UTC)  quote  ]
Message
*facepalm*

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

i'm an eeeeediot!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Fri 12 Mar 2010 07:21 PM (UTC)  quote  ]
Message
Just WindowText ... whatever.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Fri 12 Mar 2010 12:48 AM (UTC)  quote  ]
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!
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Thu 11 Mar 2010 11:47 PM (UTC)  quote  ]
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!
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 11 Mar 2010 11:43 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,772 posts)  [Biography] bio   Forum Administrator
Date Thu 11 Mar 2010 10:05 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Thu 11 Mar 2010 09:32 PM (UTC)  quote  ]
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%


[Go to top] top

Posted by Dacrian   Australia  (18 posts)  [Biography] bio
Date Mon 01 Feb 2010 10:03 PM (UTC)  quote  ]

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

Message
Edit: See below :)
[Go to top] 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.


3,008 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]