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 Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #75 on Wed 14 Mar 2012 08:56 PM (UTC)
Message
Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.


Inside Lua regular expressions you can "escape" the square brackets by putting % in front of them. eg. %[

- Nick Gammon

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

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #76 on Wed 14 Mar 2012 10:35 PM (UTC)

Amended on Wed 14 Mar 2012 10:42 PM (UTC) by Jsportive-Thalanvor

Message
that would mean something like this?


if not string.match (line, "^%[ [%a%d]%]: ")



"match bracket space [all.letters all.digits] bracket colon space"


did i got it a bit right?

[EDIT] nope, i didn't. got the title to show, but not the items worn. :(
Top

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #77 on Wed 14 Mar 2012 10:44 PM (UTC)
Message
this is the alias:


require "wait"

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

local win = GetPluginID () .. "Equipment"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 8, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)
end -- if

-- request equipment

Send "eq"

-- wait for equipment to start

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

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

local equipment = {}
local max_width = WindowTextWidth (win, font, "You are using:")

-- loop until end of equipment

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

-- see if end of equipment
  if not string.match (line, "^%[ [%a%d]%]: ") then
   break
  end -- if

-- save equipment line
  table.insert (equipment, 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 * (#equipment + 2) + 10

-- make window correct size

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

-- heading line

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

-- draw each equipment line

local y = font_height * 2 + 5

for i, styles in pairs (equipment) 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 equipment item

WindowShow (win, true)

end)  -- end of coroutine
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #78 on Wed 14 Mar 2012 11:58 PM (UTC)
Message
Can you give more information please. Not just quote tiny parts of what you are trying to match on. So you've posted the alias. Now post the entire thing (lines) from the MUD you are trying to match on.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #79 on Wed 14 Mar 2012 11:59 PM (UTC)

Amended on Thu 15 Mar 2012 12:03 AM (UTC) by Nick Gammon

Message
Jsportive-Thalanvor said:

this is the alias:


Not it isn't. If it was the alias I would see it inside <aliases> ... </aliases>

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.


^^^^^
Please read that.

- Nick Gammon

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

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #80 on Thu 15 Mar 2012 02:03 AM (UTC)
Message


<aliases>
  <alias
   name="equi"
   match="equi"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>require "wait"

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

local win = GetPluginID () .. "Equipment"
local font = "f"

if not WindowInfo (win, 1) then
  WindowCreate (win, 0, 0, 0, 0, 8, 0, 0)
  WindowFont (win, font, "Lucida Console", 9)
end -- if

-- request equipment

Send "eq"

-- wait for equipment to start

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

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

local equipment = {}
local max_width = WindowTextWidth (win, font, "You are using:")

-- loop until end of equipment

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

-- see if end of equipment
  if not string.match (line, "^%[ [%a%d]%]: ") then
   break
  end -- if

-- save equipment line
  table.insert (equipment, 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 * (#equipment + 2) + 10

-- make window correct size

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

-- heading line

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

-- draw each equipment line

local y = font_height * 2 + 5

for i, styles in pairs (equipment) 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 equipment item

WindowShow (win, true)

end)  -- end of coroutine</send>
  </alias>
</aliases>
Top

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #81 on Thu 15 Mar 2012 02:04 AM (UTC)
Message

You are using:
[ Used as light       ]: (Invis) (Glow) A Creative Spark (41)
[ Worn on head        ]: (Invis) (Glow) >.: !Press! Hat :.< (71)
[ Worn on eyes        ]: (>Amethyst Eye Lens<) (41)
[ Worn on left ear    ]: A Feather of a Fiery Phoenix (56)
[ Worn on right ear   ]: A Feather of a Fiery Phoenix (56)
[ Worn around neck    ]: (Invis) (Glow) >.: Creative License :.< (71)
[ Worn around neck    ]: (Invis) (Glow) >.: Creative License :.< (71)
[ Worn on back        ]: (Invis) (Glow) >.: Fact Checking Duty :.< (71)
[ Pinned to chest1    ]: (K) (Glow) (Hum) Academy Graduation Medal (1)
[ Worn on torso       ]: (Invis) (Hum) Emerald Gabardine (41)
[ Worn around body    ]: Cantera Adoquin Body Armor (41)
[ Worn about waist    ]: (Invis) (Glow) >.: $$$uperman Brief$$$ :.< (71)
[ Worn on arms        ]: (Invis) (Glow) Scrivener's ((!Might!)) (41)
[ Worn on left wrist  ]: (Invis) (Glow) >.: Midgaard Memorial Plastic Bracelet :.< (71)
[ Worn on right wrist ]: (Invis) (Glow) >.: Midgaard Memorial Plastic Bracelet :.< (71)
[ Worn on hands       ]: (>BloodStone Gauntlets<) (41)
[ Worn on left finger ]: (Invis) (Glow) -< Claddagh Ring >- (56)
[ Worn on right finger]: (Invis) (Glow) -< Claddagh Ring >- (56)
[ Worn on legs        ]: (>Lava Shin Guards<) (41)
[ Worn on feet        ]: (Invis) (Glow) A *Brand* New Brain (41)
[ Primary Weapon      ]: (K) a no-dachi (70)
[ Off-Hand Weapon     ]: (Glow) (Hum) Erato's Awakener Of Desire (70)
[ Floating nearby     ]: (K) (Glow) (Hum) (+) Whirlwind Whisper (+) (1)
Top

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #82 on Thu 15 Mar 2012 11:14 AM (UTC)
Message
got help from a different direction:


if not string.match (line, "^%[.*%]:") then


Top

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #83 on Wed 21 Mar 2012 11:58 PM (UTC)
Message
to drag the window around, does it has to be a plugin?
i know i like it when my inv and 2 backpacks are resizing at will on my right side of the window, because they see eachother.

but i would like to drag my equipment window around, which is created according to the inv alias.
cause it's size is stationary.

i read about the dragging, but i couldn't find the part where i can just copy/paste a specific part into my alias.
Top

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #84 on Thu 22 Mar 2012 12:56 PM (UTC)

Amended on Fri 23 Mar 2012 05:38 PM (UTC) by Ashleykitsune

Message
I need some help trying to figure out how to do this. I've searched this forum up and down using words I thought would relate to what I'm trying to do.

I want to use this code...


local battle = {}
local max_width = WindowTextWidth (win, font, "Battle")

-- loop until end of Battle text

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

  -- see if end of inventory

  if string.match (line, "&amp;lt;Battle&amp;gt; Input command for *. +attack +item +switch +run") then
    break
  end -- if

  -- save battle line
  table.insert (battle, styles)



and make it break up multiple values on each line that are separated by the pipe character so I can turn them into variables and / or table values

For instance,

|---oxooso-----------|----------xoxoxs----|
|Curtis              |                    |
|Fang                |Rat                 |
|--------------------|--------------------|
|Joe                 |                    |
|Jason               |Bird                |
|--------------------|--------------------|
<Battle> Input command for Fang. +attack +item +switch +run 



I want to be able to turn each of these "table cells" into an actual table value so I can use them later (by displaying them in a mini window.

To explain the output above, Curtis owns a creature called Fang. Fang is a Rat. Joe owns a creature called Jason. Jason is a Bird.


Is there a simple way to do this, or should I follow the guidance on FAQ #37 and create multiple triggers to accomplish this?

In this case I simply need to have six seperate table items that I can refer to. I might consider using subtables to put "Fang" and "Rat" under "Curtis" and same with Joe.

This data gets refreshed during each turn where the "creature" might change.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #85 on Fri 23 Mar 2012 03:06 AM (UTC)
Message
All this stuff follows the basic idea in FAQ 37. You find a starting pattern (eg. "Your inventory is:"). You capture lines until an end pattern (eg. "End of inventory"). If there is no specific end pattern you just capture lines "that look like inventory".

In your case your starting line seems to be some "=" signs followed by one or more of O, X, S and so on. So that should be easy.

And the end seems to start with "<Battle>". So that's easy too.

As for the middle lines, excepting the hyphen lines, you should be able to break up the data, quite possibly by column position, trim trailing spaces, convert to numbers where appropriate, and save into a table.

- Nick Gammon

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

Posted by Ashleykitsune   (33 posts)  Bio
Date Reply #86 on Sun 25 Mar 2012 02:42 PM (UTC)
Message
Nick Gammon said:

All this stuff follows the basic idea in FAQ 37. You find a starting pattern (eg. "Your inventory is:"). You capture lines until an end pattern (eg. "End of inventory"). If there is no specific end pattern you just capture lines "that look like inventory".

In your case your starting line seems to be some "=" signs followed by one or more of O, X, S and so on. So that should be easy.

And the end seems to start with "<Battle>". So that's easy too.

As for the middle lines, excepting the hyphen lines, you should be able to break up the data, quite possibly by column position, trim trailing spaces, convert to numbers where appropriate, and save into a table.


I've already been able to put the data into a miniwindow, but I haven't quite been able to figure out how to turn the data into variables. I have no programming experience whatsoever (except formula building in Excel, which doesn't count), so I'm pretty much running with my head cut off trying to figure this out.

I'm the type of person who needs to understand every little thing about something to get that "aha!" moment where everything just clicks.




for instance,

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


I understand that "while true do" is a conditional statement.
I understand that "local line" is creating a variable called "line".
I also understand what " wait.match ("*", trigger_flag.OmitFromOutput)" is doing

but I don't really understand why/what the "wildcards, styles" part is doing here.


And although I really want to understand how that works, I REALLY want to know how to brake up a line of output into variables without creating a second trigger, and resorting to wildcards.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #87 on Mon 26 Mar 2012 03:42 AM (UTC)
Message
It will help to read the Programming in Lua book. Quite a nice read.

Anyway, functions in Lua can return multiple things.

So for a line like this:


line, wildcards, styles = wait.match (...)


We assume that wait.match is returning 3 things. And from the names we guess that we are getting back the matching line, any wildcards, and the style runs (the colours). There is only one wildcard in this particular case, so wildcards [1] and 'line' are going to be the same thing.

Your data looked pretty positional to me (ie. fixed-width) so the simplest thing would be to take "line" and just break it up. Say the first part was 20 characters long (after the "|" character) you might say:


mobname = string.sub (line, 2, 20)


Where 2 is the start column, and 20 is the end column.

And so on for the other stuff.

- Nick Gammon

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

Posted by Jsportive-Thalanvor   Netherlands  (71 posts)  Bio
Date Reply #88 on Thu 12 Apr 2012 07:10 PM (UTC)

Amended on Thu 12 Apr 2012 07:19 PM (UTC) by Jsportive-Thalanvor

Message
I have had quite some succes in creating several windows for different containers in Aardwolf.

but i noticed a different problem, when storing huge amounts of potions in a single bag.

I was given the following string.match to capture the amounts of a single named item

 if not string.match (line, "^%([ %d]%d%) ") then


But it only works when it's a 2 digit amount:

(46) Potion


when i get to a 3 digit amount:

(101) Potion

then the window dissapears.

Any idea's?
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #89 on Sat 14 Apr 2012 09:21 AM (UTC)
Message
Template:regexp Regular expressions
  • Regular expressions (as used in triggers and aliases) are documented on the Regular expression tips forum page.
  • Also see how Lua string matching patterns work, as documented on the Lua string.find page.



 if not string.match (line, "^%([ %d]%d%) ") then


Would indeed match 2 digit numbers. Maybe:


 if not string.match (line, "^%([ %d]%d+%) ") then

- 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,526 views.

This is page 6, 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.