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.
 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Inventory Capture Problem with detecting my Prompt

Inventory Capture Problem with detecting my Prompt

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


Posted by Carsinix   (8 posts)  Bio
Date Thu 31 Jul 2014 08:06 PM (UTC)
Message
So I have been following Nick Gammons guide on making an inventory capture to a miniwindow and I can not get it to detect my prompt to end the capture

Here is what my inventory list displays as
[You are carrying 4 of 41 items]
[You have a total weight of 633/1260]
a Transporter device
a juicy apple
a bottle of cod liver oil
a Dark Void

4742H 98310M 45075V (100) Can Now RemortTNL Level: 50 [Inside] [Day]->

And here is my code


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 * of * items] " , 10)

if not x then
	ColourNote ("white", "blue", "No Inventory")
	end -- if
	
	local inv = {}
	local max_width = WindowTextWidth (win, font, "Inventory")
	-- loop untinl end of inventory

while true do
	local line, wildcards, styles = wait.match ("*")
	
	-- see if end of inventory
	if string.match (line, "(\d+)H (\d+)M (\d+)V \(\d+\) .+ [\w+]\-\>") 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

require "tprint"

tprint (inv)





end) -- end of coroutine



If I change it so it ends at (a Dark Void) it works correctly.

so im not sure what im doing wrong here. Is it possible to have it end at the blank line before my prompt?

I checked my regexp converstion of my prompt at regexr.com and it detects the prompt. Ive even tried adding ^ to the start. any help would be much appreciated.

Also i dont even get a fail message when I have my prompt in there.
Top

Posted by Carsinix   (8 posts)  Bio
Date Reply #1 on Thu 31 Jul 2014 10:03 PM (UTC)
Message
Well I figured a work around, but i would still like to know why it wont trigger off the prompt. I can run a trigger and my trigger fires, but this alias isint working with it.

My work around is just changing

 if string.match (line, "(\d+)H (\d+)M (\d+)V \(\d+\) .+ [\w+]\-\>") then
	break
	end -- if


to


if not string.match (line, "[A-Za-z0-9]") then
break
end -- if
Top

Posted by Shadowfyr   USA  (1,788 posts)  Bio
Date Reply #2 on Thu 31 Jul 2014 10:05 PM (UTC)
Message
Uh. Been a while, but.. at the end of your prompt you have:

[Day]->

But your regex says '[\w+]\-\>', which translates to "any letter or _ followed by ->", right? So, it will never match on your [Day] or [Inside] parts. Or, that would be my guess at least. You would need to either remove the [\w+], in which case it would just not care, I think, if the other stuff is in there, or, either "[\[\w+\]][\[\w+\]]\-\>", for exactly two such bracketed things, or, to be more clever "[\[\w+\]]{0,2}\-\>", which would, unless I am way too rusty, give you "between 0 and 2" bracketed items (on the chance the prompt might, in some cases, be missing them.
Top

Posted by Nick Gammon   Australia  (23,121 posts)  Bio   Forum Administrator
Date Reply #3 on Fri 01 Aug 2014 03:14 AM (UTC)
Message
Quote:

if string.match (line, "(\d+)H (\d+)M (\d+)V \(\d+\) .+ [\w+]\-\>") then


But this is a PCRE-style regular expression, not a Lua one.

Lua regular expressions use somewhat different syntax, as described here:

http://www.gammon.com.au/scripts/doc.php?lua=string.find

In particular, to match digits you use %d not \d. Similarly for \w.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


16,989 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.