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 ➜ Getting Started ➜ Video showing how to make an inventory alias

Video showing how to make an inventory alias

Posting of new messages is disabled at present.

Refresh page


Pages: 1  2  3  4 5  6  7  8  9  10  

Posted by Val   (27 posts)  Bio
Date Reply #45 on Sat 12 Mar 2011 01:20 PM (UTC)
Message
Hi

One last thing on this subject and I will be done, and thanks for your help so far.

To see my inventory I get a double line after 'you are carrying' then the list of items I have. The code above stops as soon as it sees the line as it thinks the end of the inventory has been reached. Is there a way to have 'you are carrying:' as the search line but make it skip the next two lines before the list.

I've tried making the lines the trigger, but both lines are the same, so it stops as soon as the second line hits.

Please see below for what I mean

you are carrying:

-------------
-------------
A large brown sack
A dagger
Healing potions (5)

------------

Thanks

Val
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #46 on Sun 13 Mar 2011 12:14 AM (UTC)

Amended on Sun 13 Mar 2011 01:34 AM (UTC) by Nick Gammon

Message
In the alias, where it says:


  -- save inventory line
  table.insert (inv, styles)
  -- work out max width
  max_width = math.max (max_width, WindowTextWidth (win, font, line))


... just test for lines you don't want. Eg.



  if line ~= "-------------" then
    -- save inventory line
    table.insert (inv, styles)
    -- work out max width
    max_width = math.max (max_width, WindowTextWidth (win, font, line))
  end -- if wanted line

- Nick Gammon

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

Posted by Val   (27 posts)  Bio
Date Reply #47 on Sun 13 Mar 2011 01:17 AM (UTC)
Message
Hi

Its getting late for me so I may be off track,

I inserted the line -

if line ~= "-------------" then

above the existing line -

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

But now I get an error

Immediate execution
[string "Alias: "]:82: unexpected symbol near ')'

That line happens to be the

ShowWin (win, false)

just befire the end of the program.

I then took the whole section printed above and added it, but got the same result I got before, the word Inventory with nothing below it.

Sorry for the inconvenience and I will give it another bash tomorrow :)

Val
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #48 on Sun 13 Mar 2011 01:33 AM (UTC)
Message
Did you add in the "end" I had as well?

- Nick Gammon

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

Posted by Val   (27 posts)  Bio
Date Reply #49 on Mon 14 Mar 2011 07:19 PM (UTC)
Message
Hi

I did,,,after you mentioned it :p

But I still get the same as I started with, I get the miniwindow, with the word inventory on it, but no contents.

It must be going through the process because I dont get the reply 'no inventory received'

Any thoughts on where I went wrong?

if line ~= "-------------------------------------------------------" then

-- save inventory line


table.insert (comp, styles)
-- work out max width
max_width = math.max (max_width, WindowTextWidth (win, font, line))
end -- test


My iventry box on screen looks like this:

Inventry
-------------------------------------------------------

A dagger
kit (10)

-------------------------------------------------------

(also no spaces from the border)

Sorry to be a pain, but I am learning a lot doing this

Val

Top

Posted by Ham   (2 posts)  Bio
Date Reply #50 on Wed 18 Jan 2012 04:25 AM (UTC)
Message
My miniwindow is blank with the exception of the word Inventory. The MUD I am applying this to is Achaea and it's inventory setup is different:

Ex)
You are holding:
obsidian dagger, 5 ebony vials, 2 oaken vials, a cherry wood vial, a simple fishing pole, a bait bucket, a snow blossom vial.
You are wearing:
a suit of ring mail, a canvas backpack

I attempted to change some lines as needed, but am uncertain as to what else I need or what is wrong with what I altered. Any input would be appreciated. Thanks!

The current script I have is as follows:

Quote:
require "wait"

wait.make (function ()



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

Send "inventory"

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

if not x then
ColourNote ("white", "red", "No inventory was received within 10 seconds.")
return
end

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

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

if not string.match (line, "^You are wearing:") then
break
end

table.insert (inv, styles)
max_width = math.max (max_width, WindowTextWidth (win, font, line))
end


local font_height = WindowFontInfo (win, font, 1)

local window_width = max_width + 10
local window_height = font_height * (#inv + 2) + 10

WindowCreate (win, 0, 0, window_width, window_height, 6, 0, ColourNameToRGB "#373737")
WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)

WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB "yellow")

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
y = y + font_height

end

WindowShow (win, true)



end)
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #51 on Thu 19 Jan 2012 07:08 PM (UTC)
Message

if not string.match (line, "^You are wearing:") then
  break
end


That will make it stop as soon as it gets a line which doesn't match "You are wearing:". You probably want to lose the word "not", because you want go keep going until you do get the line, not until you don't get it.

- Nick Gammon

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

Posted by Ham   (2 posts)  Bio
Date Reply #52 on Thu 19 Jan 2012 07:37 PM (UTC)
Message
And that did the trick. Thank you very much, good sir.
Top

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #53 on Sun 04 Mar 2012 07:28 PM (UTC)
Message
Hi, this tutotorial is great!
I was able to create an Alias without much dificulty. However I quickly realized that I would need to convert this into a trigger.
After half a day of work, I was able to work out nearly all the bugs, however there's one thing I'm not sure how to do.

This is what the text looks like that I want put into a miniwindow:

-- Planter ---------------------------------------
| 1 | The Hondew Berry has sprouted.
| 2 | The Hondew Berry has sprouted.
| 3 | The Hondew Berry has sprouted.
|*4*| A Charti Berry was planted here.
--------------------------------------------------
 | P# | Plant a berry    |
 | W# | Water a plant    |
 | H# | Harvest berries  |
 | X# | Destroy a plant  |
 | Q  | Quit             |
 -------------------------
<Planter> What will you do?

And here's a copy of my conversion:

<triggers>
  <trigger
   enabled="y"
   match="-- Planter ---------------------------------------"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":planter"
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

-- wait for inventory to start

local x = wait.match ("-- Planter*", 10, trigger_flag.OmitFromOutput)

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

local planter = {}
local max_width = WindowTextWidth (win, font, "Planter")

-- loop until end of planter data

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

-- see if end of planter data

  if string.match (line, "&lt;Planter&gt; What will you do?") then
    break
  end -- if

  -- save planter data lines
  table.insert (planter, 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 * (#planter + 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, "Planter", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (planter) 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 planter data item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </trigger>
</triggers>


The issue with this lies in that the trigger
"-- Planter ---------------------------------------"


and the variable

local x = wait.match ("-- Planter*", 10, trigger_flag.OmitFromOutput)


are the same line. If I change it to this:
local x = wait.match ("|*", 10, trigger_flag.OmitFromOutput)


it gives me this:

 Planter 
| 2 | The Hondew Berry has sprouted.
| 3 | The Hondew Berry has sprouted.
|*4*| A Charti Berry was planted here.
--------------------------------------------------
 | P# | Plant a berry    |
 | W# | Water a plant    |
 | H# | Harvest berries  |
 | X# | Destroy a plant  |
 | Q  | Quit             |
 -------------------------

So it completely removes the first line. Can I get it to work using the same line as the trigger?

Thanks
Top

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #54 on Sun 04 Mar 2012 07:32 PM (UTC)
Message
Just in case you wanted to know why I needed to convert it into a trigger - each time you issue a command, such as p1 to plant a seed at position 1, or w1 to water that position (etc), the data gets refreshed showing what has changed to include the seeds planted, or the watered status (indicated by the *#*).

By using a trigger I get around having to use +planter to update the window.

I'm also working on away to use the second Alias code you had to close the window after I quit the session, although simply using "Q" as a trigger here won't work.
:)
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #55 on Sun 04 Mar 2012 08:39 PM (UTC)
Message
Well you don't need most of this, because being a trigger, you *know* you have the first line:


-- wait for inventory to start

local x = wait.match ("-- Planter*", 10, trigger_flag.OmitFromOutput)

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

local planter = {}


So you can probably replace it with:


local planter = { "%0" }


The %0 is "the matching line" from the trigger, so you pre-insert that line, and then the others get added as they arrive.

(untested though)

- Nick Gammon

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

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #56 on Mon 05 Mar 2012 04:02 PM (UTC)

Amended on Mon 05 Mar 2012 04:07 PM (UTC) by Ashleykitsune

Message
I attempted what you suggested but I ended up getting error after error. Each time I tried to fix an error a new one would show up. I was probably just making things worse and worse.

In other news, I was able to get the helpfil working. Turns out since I have Windows Vista, I needed to download something to allow me to view older helpfiles.

This is the error text I get when I follow your suggestion.


stack traceback:
        [C]: in function 'ipairs'
        [string "Trigger: "]:56: in function <[string "Trigger: "]:3>
Run-time error
World: PKFusion
Function/Sub: wait.trigger_resume called by trigger
Reason: processing trigger "wait_trigger_460"
C:\Program Files\MUs\MUSHClient\lua\wait.lua:67: [string "Trigger: "]:56: bad argument #1 to 'ipairs' (table expected, got string)
stack traceback:
        [C]: in function 'error'
        C:\Program Files\MUs\MUSHClient\lua\wait.lua:67: in function <C:\Program Files\MUs\MUSHClient\lua\wait.lua:59>


one time if even said this:
Error raised in trigger function (in wait module)


I'm going to keep looking but I appreciate the help.

The "ipairs" that it is talking about is where the code says " for _, style in ipairs (styles) do"
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #57 on Mon 05 Mar 2012 08:17 PM (UTC)
Message
Show your code with my suggested modification in it please.

- Nick Gammon

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

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #58 on Tue 06 Mar 2012 01:55 PM (UTC)
Message
Here's the entire trigger. I hate to be a bother but I really appreciate you helping me understand how all this works.


<triggers>
  <trigger
   enabled="y"
   match="-- Planter ---------------------------------------"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":planter"
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

local planter = { "%0" }
local max_width = WindowTextWidth (win, font, "Planter")

-- loop until end of planter data

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

-- see if end of planter data

  if string.match (line, "&lt;Planter&gt; What will you do?") then
    break
  end -- if

  -- save planter data lines
  table.insert (planter, 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 * (#planter + 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, "Planter", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (planter) 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 planter data item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </trigger>
</triggers>
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #59 on Tue 06 Mar 2012 08:26 PM (UTC)

Amended on Tue 06 Mar 2012 08:27 PM (UTC) by Nick Gammon

Message
Oops. I made a mistake. The first table entry should have been the styles for that line, not just the line. This one works:


<triggers>
  <trigger
   enabled="y"
   match="-- Planter ---------------------------------------"
   send_to="14"
   sequence="100"
  >
  <send>require "wait"

wait.make (function ()  -- coroutine starts here


local win = GetPluginID () .. ":planter"
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

local planter = { TriggerStyleRuns }
local max_width = WindowTextWidth (win, font, "Planter")

-- loop until end of planter data

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

-- see if end of planter data

  if string.match (line, "&lt;Planter&gt; What will you do?") then
    break
  end -- if

  -- save planter data lines
  table.insert (planter, 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 * (#planter + 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, "Planter", 5, 5, 0, 0, ColourNameToRGB  "yellow")

-- draw each inventory line

local y = font_height * 2 + 5

for i, styles in ipairs (planter) 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 planter data item

WindowShow (win, true)


end)   -- end of coroutine

</send>
  </trigger>
</triggers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.

- 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.


434,523 views.

This is page 4, subject is 10 pages long:  [Previous page]  1  2  3  4 5  6  7  8  9  10  [Next page]

Posting of new messages is disabled at present.

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.