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 #30 on Fri 14 Jan 2011 03:37 AM (UTC)
Message
OK, but the Lua string.match uses the % character, whereas in a trigger or alias (which uses the PCRE matching) it would be the \ character.

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.

- Nick Gammon

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

Posted by Tseris   (98 posts)  Bio
Date Reply #31 on Fri 14 Jan 2011 05:05 AM (UTC)
Message
Okay, now it is giving me the following error, a few seconds after it sends "inventory" to the output window:


Error raised in timer function (in wait module).
stack traceback:
        [C]: in function 'match'
        [string "Alias: "]:29: in function <[string "Alias: "]:3>
Run-time error
Plugin: Inventory_Miniwindow_Demo (called from world: Animus)
Function/Sub: wait.timer_resume called by timer
Reason: processing timer "wait_trigger_114"
C:\Users\Nihilism\Desktop\MUSHclient\lua\wait.lua:51: [string "Alias: "]:29: bad argument #1 to 'match' (string expected, got nil)
stack traceback:
        [C]: in function 'error'
        C:\Users\Nihilism\Desktop\MUSHclient\lua\wait.lua:51: in function <C:\Users\Nihilism\Desktop\MUSHclient\lua\wait.lua:43>




Im using MUSHclient v4.61 and I looked in wait.lua and it seemed like the changes listed on page 1 were already there, but just to be sure I pasted the changed sections anyway, still gives same error. By the way I appreciate the help, very new to this.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #32 on Fri 14 Jan 2011 05:29 AM (UTC)
Message
Right, it is hard to debug without actually seeing what you have done. Can you paste your alias please?

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.


- Nick Gammon

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

Posted by Tseris   (98 posts)  Bio
Date Reply #33 on Fri 14 Jan 2011 05:58 AM (UTC)

Amended on Fri 14 Jan 2011 06:16 AM (UTC) by Tseris

Message

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Sunday, May 02, 2010, 3:37 PM -->
<!-- MuClient version 4.51 -->

<!-- Plugin "Inventory_Miniwindow_Demo" generated by Plugin Wizard -->

<muclient>
<plugin
   name="Inventory_Miniwindow_Demo"
   author="Nick Gammon"
   id="e49156f49854904ea8b90223"
   language="Lua"
   purpose="Shows Inventory in a miniwindow"
   save_state="y"
   date_written="2010-05-02 15:35:51"
   requires="4.51"
   version="1.0"
   >
<description trim="y">
<![CDATA[
Type "inv" to see your inventory in a miniwindow.
]]>
</description>

</plugin>


<!--  Aliases  -->

<aliases>
  <alias
   match="inv"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>

wait.make (function ()  -- coroutine starts here
  
  -- request inventory
  
  Send "inventory"
  
  
  -- wait for inventory to start
  
  local x = wait.match ("*You are carrying:", 10, trigger_flag.OmitFromOutput)
  
  if not x then
    ColourNote ("white", "blue", "No inventory received within 10 seconds")
    return
  end -- if
  
  local inv = {}
  local max_width = WindowTextWidth (win, font, "Inventory")
  
  -- loop until end of inventory
  
  while true do
    local line, wildcards, styles = wait.match ("*", trigger_flag.OmitFromOutput)
  
    -- see if end of inventory
  
    if string.match (line, "^%[Cor") 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
  
  local font_height = WindowFontInfo (win, font, 1)
  
  local window_width = 5000
  local window_height = 8000
  
  -- make window correct size
  
  WindowCreate (win, 
                 windowinfo.window_left, 
                 windowinfo.window_top, 
                 window_width, window_height,              -- width, height
                 windowinfo.window_mode,   
                 windowinfo.window_flags,
                 ColourNameToRGB "black") 
                   
  -- draw border
  WindowRectOp (win, 5, 0, 0, 0, 0, 5, 15 + 0x1000)
  
  -- add the drag handler so they can move the window around
  movewindow.add_drag_handler (win, 0, 0, 0, font_height)
  
  -- heading line
  WindowText (win, font, "Inventory", 5, 5, 0, 0, ColourNameToRGB  "yellow")
  
  -- draw each inventory line
  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 -- for
    y = y + font_height
  
  end -- for each inventory item
  
  -- now show the window
  WindowShow (win, true)

end)   -- end of coroutine

</send>
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[

require "wait"  -- for waiting for inventory lines
require "movewindow"  -- load the movewindow.lua module

win = GetPluginID () .. "_inventory"
font = "f"

function OnPluginInstall ()

  -- install the window movement handler, get back the window position
  windowinfo = movewindow.install (win, 6)  -- default to 6 (on top right)
  
  -- make window so I can grab the font info
  WindowCreate (win, 0, 0, 0, 0, 1, 0, 0)

  -- add the font                 
  WindowFont (win, font, "Lucida Console", 9)  
    
end -- OnPluginInstall

function OnPluginSaveState ()
  -- save window current location for next time  
  movewindow.save_state (win)
end -- function OnPluginSaveState


]]>
</script>


</muclient>


Edit: converted clipboard forum codes

Edit: Discovered the problem, changed the line


 -- loop until end of inventory
  
  while true do
    local line, wildcards, styles = wait.match ("*", trigger_flag.OmitFromOutput)


to


 -- loop until end of inventory
  
  while true do
    local line, wildcards, styles = wait.match ("*", 0, trigger_flag.OmitFromOutput)


So it no longer errors, and does omit the inventory list from the main output window, but now it waits for another command to be entered (or even an empty string) before drawing the miniwindow.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #34 on Fri 14 Jan 2011 06:31 AM (UTC)
Message
Well done for spotting that! As for the wait, it is probably waiting for the prompt line which you are testing for. Maybe if you force it out somehow? Instead of:


Send "inventory"


you might do:



Send "inventory"
Send "look"



Or anything that forces out a prompt after the inventory.

- Nick Gammon

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

Posted by Tseris   (98 posts)  Bio
Date Reply #35 on Fri 14 Jan 2011 03:46 PM (UTC)
Message
Awesome, thank you. Ive used this basic format and have been able to create miniwindows for inventory, equipment, and score screens. Im also interested in how to have these windows occupy the same space but only display one at a time. My general thought is that you would make one window, add hotspots at the bottom for tabs, then when a tab is clicked you stop showing the current miniwindow and redraw the new one.

Ive downloaded the plugin here:

http://www.gammon.com.au/forum/?id=8936

and attempted to dissect it to figure out how you are having the scripts switch between windows but at the moment its boggling me.

Another concern I have is maintaining positioning when switching windows. For example, if I have inventory showing and drag the window to the other side of the screen. Then I click to show equipment. Im guessing the new equipment window would draw back in the original location, and not the new location.
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #36 on Fri 14 Jan 2011 09:25 PM (UTC)

Amended on Fri 14 Jan 2011 09:27 PM (UTC) by Nick Gammon

Message
I think the tabs will be easier than maintaining multiple windows. The basic concept for tabbed windows is quite simple:


  • You have the "main" or "currently-displayed" tab which is the bulk of the window (eg. the top part if the tabs are at the bottom).

    When you need to redraw the window you draw into the main area with a simple decision based on the currently selected tab. For example:

    
    function redraw_main_window ()
      if tab == "inventory" then
        draw_inventory ()
      elseif tab == "equipment" then
        draw_equipment ()
      elseif tab == "score" then
        draw_score ()
      end -- if
    end -- function
    


    Of course you can probably see ways of improving even that code, by using a table of tabs, with the tab name as the key and the function to draw the tab as the value.

  • At the bottom you draw your tabs using rectangles and text (or pre-rendered PNG files with the tabs in them). For example:

    
    <Inventory> <Equipment> <Score>
    


    Each tab is made into a hotspot, and when the hotspot is clicked on you change the "tab" variable. Eg. if <Inventory> is clicked on you do:

    
    tab = "inventory"
    redraw_main_window ()  -- does the decision above
    


    You would have some way of knowing the current tab (eg. different colour, overlap the graphic, etc.).



With the displaying handled, the rest of the plugin handles gathering data, even if it isn't displayed right now. For example, if you get inventory information you still collect it into the inventory table, even though the inventory tab might not be visible. Then when you click on the inventory tab, it is ready to be displayed.

- Nick Gammon

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

Posted by Tseris   (98 posts)  Bio
Date Reply #37 on Wed 19 Jan 2011 10:45 PM (UTC)
Message
Thanks a ton Nick, Im working through it slowly but its coming along. One thing Ive come to is that when drawing the tabs, I followed this basic procedure:

1) draw a straight line horizontally at the bottom to separate the tabs from main window

2) use rounded rectangles for the tabs, with text drawn on top of each for tab lables

3) for the currently selected tab, draw a line the same color as the background on top of the above line so that the tab blends into the main window

Ive noticed it creates some small but odd edges at the top left and right corners of the active tab because of the rounded rectangle. I noticed you used Bezier curves to accomplish this but Im very bad with tables and I was wondering if you could explain some about how to use the Bezier's to create the rounded tab effect
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #38 on Thu 20 Jan 2011 06:22 AM (UTC)
Message
Well mine don't look that great either. :)

I tested out my code in the Immediate window with this:



win = "test_" .. GetPluginID ()  -- get a unique name, ensure not empty if outside plugin
WindowCreate (win, 0, 0, 200, 60, miniwin.pos_center_all, 0, ColourNameToRGB("white"))  -- create window
WindowShow (win,  true)  -- show it 

 -- Grid
  for i = 1, math.max (WindowInfo (win, 3), WindowInfo (win, 4)) / 20 do
    WindowLine (win, i * 20, 0, i * 20, WindowInfo (win, 4), 0xC0C0C0, miniwin.pen_solid, 1)
    WindowLine (win, 0, i * 20, WindowInfo (win, 3), i * 20, 0xC0C0C0, miniwin.pen_solid, 1)
  end -- for


tabwidth = 60
colour = ColourNameToRGB ("blue")
width = 2


  local points = {
      0,  2,                     -- start (top left)  1 .. 2
     10,  2,  10,  2,  10,  2,   -- top of tab, before curve    3 ..  8
     10, 22,  10, 22,  30, 22,   -- bottom of tab - left side   9 .. 14
     10, 22,  10, 22,  10, 22,   -- bottom of tab - right side 15 .. 20
     20, 22,  20, 22,  20,  2,   -- top of tab, after curve    21 .. 26
     22,  2,  22,  2,  22,  2,   -- finishing horizontal line  27 .. 32  
  } -- end points table
  
  -- add width
  for i = 15, #points, 2 do
    points [i] = points [i] + tabwidth - 10
  end -- for

 WindowBezier (win, table.concat (points, ","), colour, 0, width)
 WindowLine   (win, tabwidth + 10, 2, tabwidth + 200, 2, colour, 0, width) 

print (table.concat (points, ","))


The results were:



Basically it drew a Bezier curve with a line, the Bezier curve points were:


0,2,10,2,10,2,10,2,10,22,10,22,30,22,60,22,60,22,60,22,70,22,70,22,70,2,72,2,72,2,72,2


The code sort-of explains why, but I'm not that happy with the result anyway. It's explained here a bit:

http://www.gammon.com.au/mushclient/mw_shapes.htm#WindowBezier

But you might get a better result by just making a nice tab graphic in your favourite painting program, save as a PNG file, and just put a few of them next to each other (or do a separate graphic for each possible tab selected).

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #39 on Thu 20 Jan 2011 06:51 AM (UTC)
Message
If you want more detail look up "Bezier curve" in Wikipiedia, although personally I find that, after understanding the first couple of paragraphs, the maths in the rest of it goes over my head a bit.

- Nick Gammon

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

Posted by Tseris   (98 posts)  Bio
Date Reply #40 on Thu 20 Jan 2011 07:38 AM (UTC)
Message
Ive been working with it this afternoon before I got a chance to see your post, and I actually ended up having a brainstorm, with seemingly pretty good results. I drew the tabs first, then laid the main rectangle over top of it, with the bottom edge overlapping the top of the tabs by a few pixels. The result is you get the nice rounded bottom corners but the top corners are buried. Im still looking into those curves though, because theres alot more that I could do with them.
Top

Posted by Val   (27 posts)  Bio
Date Reply #41 on Fri 11 Mar 2011 12:08 AM (UTC)
Message
Hi

I'm new to this client and I seem to be struggling, after trying the first section of the video where you merely test the command I can't get to work.

I get the message -

C:\Program Files (x86)\MUSHclient\lua\wait.lua:161: [string "Alias: "]:5: attempt to call global 'send' (a nil value)
stack traceback:
[C]: ?
C:\Program Files (x86)\MUSHclient\lua\wait.lua:161: in function 'make'
[string "Alias: "]:2: in main chunk

Obviously I'm doing something silly, I just cant see it, can you point me in the right direction.

Also you mention the wait module, do I install it and if so is it the same as a plugin?

Thanks
Top

Posted by Twisol   USA  (2,257 posts)  Bio
Date Reply #42 on Fri 11 Mar 2011 01:40 AM (UTC)
Message
Val said:
C:\Program Files (x86)\MUSHclient\lua\wait.lua:161: [string "Alias: "]:5: attempt to call global 'send' (a nil value)
stack traceback:


It's "Send", not "send". The capital is important.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
Top

Posted by Nick Gammon   Australia  (23,122 posts)  Bio   Forum Administrator
Date Reply #43 on Fri 11 Mar 2011 04:31 AM (UTC)
Message
The "wait" module should be already there, as part of the "lua" subdirectory when you installed the client. The problem was the capitalization of "send", as Twisol said.

- Nick Gammon

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

Posted by Val   (27 posts)  Bio
Date Reply #44 on Sat 12 Mar 2011 01:02 PM (UTC)
Message
Thank you
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,522 views.

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