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.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ Miniwindows ➜ Module to do pop-up information windows

Module to do pop-up information windows

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


Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Mon 08 Sep 2008 05:35 AM (UTC)

Amended on Mon 08 Sep 2008 09:25 AM (UTC) by Nick Gammon

Message
To help with making miniwidows become easier to use, I have taken a break from writing plugins to write a helper module, that makes writing plugins easier. :-)

This module implements the code I used for the inventory plugin (see: http://www.gammon.com.au/forum/?id=8936) and moves part of it into a helpful external module.

The intention of this code is for providing for "mouse-over" windows, that you simply look at (like information about the current inventory item). There is no provision for hyperlinks or hotspots. However for the case of simply wanting to do a nice colourful popup window, this should be helpful.

A screenshot is in the next post in this thread.

The major feature of the popup window is that it resizes itself to exactly contain the text within it. In order to achieve that, it needs to have the entire text provided in advance, so it can calculate the number of lines (to get the height) and the maximum line width (to get the width).

To do this, you simply make a table, and by using table.insert, insert the text in the table in the order in which you want it to appear. To allow for coloured text I have implemented support for the Aardwolf colour codes (eg. @R = bold red, @g is normal green), so you simply imbed these codes into the text where required.


If you want to add additional colours, simply choose a letter that is not in use (eg. "z") and add it to the table like this:


mw.colour_conversion.z =  0xDEC4B0  -- (lightsteelblue)


Now you could use @z as a colour code as well as the existing ones.

A bit of preliminary setup is required, as indicated in the comments. To save time, and allow for player configuration, you define in advance what the font names and font sizes are going to be, and load them into the required miniwindow. At this stage the window is not shown, so this is simply preparing it for use later on.

There is also provision for aligning the window to the right (so you could make it appear to the left of a mouse-click, rather than to the right of it), and aligning to the bottom. In both cases these calculations have to be done inside mw.popup, as we don't know, until they are calculated, the width and depth of the window.

There is a "capitalize" option - I wanted this so that items like "a rusty sword" would display as "A rusty sword" - however you can't just capitalize them in advance, as the descriptions I received from the MUD might have colour codes in them. For example, you don't want to convert "@ga rusty sword" into "@Ga rusty sword" because you have changed the colour, not the word "a".



-- mw.lua

-- Helper functions for miniwindows
--

-- Author: Nick Gammon - 8th September 2008

--[[

Exposed functions are:

   mw.colourtext        - show a string with imbedded colour codes
   mw.colour_conversion - table with colour codes in it - add more if you want
   mw.strip_colours     - remove colour codes from a string
   mw.popup             - make a popup window
   
Example of making a popup window:

  require "mw"
  
  
  -- SET UP FOR POPUP WINDOWS - define colours, add fonts, make window id
  -- (DO THIS ONCE ONLY, eg. in OnPluginInstall)
  
  -- our window frame/background colours
  border_colour = 0xCCD148
  background_colour = 0x222222
  
  -- a unique ID
  infowin = GetPluginID () .. ":info"

  -- font IDs
  font_id = "popup_font"  
  heading_font_id = "popup_heading_font"  

  font_size = 8

  -- use 8 pt Dina or 10 pt Courier
  local fonts = utils.getfontfamilies ()

  -- choose a font that exists
  
  if fonts.Dina then
    font_name = "Dina"    
  elseif fonts ["Lucida Sans Unicode"] then
    font_name = "Lucida Sans Unicode"
  else
    font_size = 10
    font_name = "Courier"
  end -- if
  
  -- load fonts - mouseover window
  WindowCreate (infowin, 0, 0, 1, 1, 0, 0, 0)   -- make 1-pixel wide window
  
  -- install the fonts  (49 is modern / fixed pitch)
  WindowFont (infowin, font_id, font_name, font_size, false, false, false, false, 0, 49) 
  WindowFont (infowin, heading_font_id, font_name, font_size + 2, false, false, false, false, 0, 49)
  
    
  -- NOW DISPLAY A WINDOW
  
  -- what to say - one line per table entry, with imbedded colour codes
  
  info = { "@Ctesting 1 2 3", 
           "@GThis is a heading",
           "Line @Mwith @Bmultiple @Rcolours",
         }
  
  heading = "@MHello, @Yworld"
  left, top = 40, 50
  align_right = false
  align_bottom = false
  capitalize = true

  -- show it  
  mw.popup (infowin,           -- window name to use
            heading_font_id,   -- font to use for the heading
            font_id,           -- font to use for each line
            heading,           -- heading text
            info,              -- table of lines to show (with colour codes)
            left, top,         -- where to put it
            border_colour,     -- colour for round rectangle line
            background_colour, -- colour for background
            capitalize,        -- if true, force the first letter to upper case
            align_right,       -- if true, align right side on "Left" parameter
            align_bottom)      -- if true, align bottom side on "Top" parameter




--]]


module (..., package.seeall)

DEFAULT_COLOUR = "@w"
TRANSPARENCY_COLOUR = 0x080808
BORDER_WIDTH = 2

local BLACK = 1
local RED = 2
local GREEN = 3  
local YELLOW = 4 
local BLUE = 5 
local MAGENTA = 6 
local CYAN = 7 
local WHITE = 8

-- colour styles (eg. @r is normal red, @R is bold red)

-- @- is shown as ~
-- @@ is shown as @

-- This table uses the colours as defined in the MUSHclient ANSI tab, however the
-- defaults are shown on the right if you prefer to use those.

colour_conversion = {
   k = GetNormalColour (BLACK)   ,   -- 0x000000 
   r = GetNormalColour (RED)     ,   -- 0x000080 
   g = GetNormalColour (GREEN)   ,   -- 0x008000 
   y = GetNormalColour (YELLOW)  ,   -- 0x008080 
   b = GetNormalColour (BLUE)    ,   -- 0x800000 
   m = GetNormalColour (MAGENTA) ,   -- 0x800080 
   c = GetNormalColour (CYAN)    ,   -- 0x808000 
   w = GetNormalColour (WHITE)   ,   -- 0xC0C0C0 
   K = GetBoldColour   (BLACK)   ,   -- 0x808080 
   R = GetBoldColour   (RED)     ,   -- 0x0000FF 
   G = GetBoldColour   (GREEN)   ,   -- 0x00FF00 
   Y = GetBoldColour   (YELLOW)  ,   -- 0x00FFFF 
   B = GetBoldColour   (BLUE)    ,   -- 0xFF0000 
   M = GetBoldColour   (MAGENTA) ,   -- 0xFF00FF 
   C = GetBoldColour   (CYAN)    ,   -- 0xFFFF00 
   W = GetBoldColour   (WHITE)   ,   -- 0xFFFFFF 
   
   -- add custom colours here
   
   
  }  -- end conversion table

  
  
-- displays text with colour codes imbedded
-- 
-- win: window to use
-- font_id : font to use
-- Text : what to display
-- Left, Top, Right, Bottom : where to display it
-- Capitalize : if true, turn the first letter into upper-case

function colourtext (win, font_id, Text, Left, Top, Right, Bottom, Capitalize)

  if Text:match ("@") then
    local x = Left  -- current x position
    local need_caps = Capitalize
    
    Text = Text:gsub ("@%-", "~")    -- fix tildes
    Text = Text:gsub ("@@", "\0")  -- change @@ to 0x00
    
    -- make sure we start with @ or gsub doesn't work properly
    if Text:sub (1, 1) ~= "@" then
      Text = DEFAULT_COLOUR .. Text
    end -- if
    
    for colour, text in Text:gmatch ("@(%a)([^@]+)") do
      text = text:gsub ("%z", "@") -- put any @ characters back
      
      if need_caps then
        local count
        text, count = text:gsub ("%a", string.upper, 1)
        need_caps = count == 0 -- if not done, still need to capitalize yet
      end -- if
      
      if #text > 0 then
        x = x + WindowText (win, font_id, text, x, Top, Right, Bottom, 
                            colour_conversion [colour] or GetNormalColour (WHITE))
      end -- some text to display
          
    end -- for each colour run
    
    return x
  end -- if
  

  if Capitalize then
    Text = Text:gsub ("%a", string.upper, 1)
  end -- if leading caps wanted
  
  return WindowText (win, font_id, Text, Left, Top, Right, Bottom, 
                    colour_conversion [DEFAULT_COLOUR] or GetNormalColour (WHITE))

end -- colourtext

-- take a string, and remove colour codes from it (eg. "@Ghello" becomes "hello"
function strip_colours (s)
  s = s:gsub ("@%-", "~")    -- fix tildes
  s = s:gsub ("@@", "\0")  -- change @@ to 0x00
  s = s:gsub ("@%a([^@]*)", "%1")
  return (s:gsub ("%z", "@")) -- put @ back
end -- strip_colours


function popup (win,    -- window name to use
                heading_font_id,   -- font to use for the heading
                font_id,           -- font to use for each line
                heading,           -- heading text
                info,              -- table of lines to show (with colour codes)
                Left, Top,         -- where to put it
                border_colour,     -- colour for round rectangle line
                background_colour, -- colour for background
                capitalize,        -- if true, force the first letter to be upper case
                align_right,       -- if true, align right side on "Left" parameter
                align_bottom)      -- if true, align bottom side on "Top" parameter

--[[

  A prerequisite is to create the window first and load the two fonts into it.
  This only needs to be done once, and as it may take a bit of code to select a font that actually
  exists, I prefer to not do it here.
  
  Example code:

  infowin = GetPluginID () .. ":info"
  font_id = "popup_font"  
  heading_font_id = "popup_heading_font"  

  font_size = 8

  -- use 8 pt Dina or Lucida Sans, or 10 pt Courier
  local fonts = utils.getfontfamilies ()

  if fonts.Dina then
    font_name = "Dina"    
  elseif fonts ["Lucida Sans Unicode"] then
    font_name = "Lucida Sans Unicode"
  else
    font_size = 10
    font_name = "Courier"
  end -- if

  
  -- load fonts - mouseover window
  WindowCreate (infowin, 0, 0, 1, 1, 0, 0, 0)   -- make 1-pixel wide window
  
  -- install the fonts  (49 is modern / fixed pitch)
  WindowFont (infowin, font_id, font_name, font_size, false, false, false, false, 0, 49) 
  WindowFont (infowin, heading_font_id, font_name, font_size + 2, false, false, false, false, 0, 49)
  

--]]

                
  assert (WindowInfo (win, 1), "Window " .. win .. " must already exist")
  assert (WindowFontInfo (win, heading_font_id, 1), "No font " .. heading_font_id .. " in " .. win)
  assert (WindowFontInfo (win, font_id, 1), "No font " .. font_id .. " in " .. win)
  
  local font_height = WindowFontInfo (win, font_id, 1)
  local font_leading = WindowFontInfo (win, font_id, 4) + WindowFontInfo (win, font_id, 5)
  local heading_font_height = WindowFontInfo (win, heading_font_id, 1)
  
  -- find text width - minus colour codes  
  
  local infowidth = 0 
  local infoheight = 0 
  
  -- calculate heading width and height
  if heading and #heading > 0 then
    infowidth  = WindowTextWidth (win, heading_font_id, strip_colours (heading))
    infoheight = heading_font_height
  end -- have a heading

  -- calculate remaining width and height
  for _, v in ipairs (info) do
    infowidth  = math.max (infowidth, WindowTextWidth (win, font_id, strip_colours (v)))
    infoheight = infoheight + font_height
  end -- for

  infowidth = infowidth + (2 * BORDER_WIDTH) +    -- leave room for border
                WindowFontInfo (win, font_id, 6)  -- one character width extra
                
  infoheight = infoheight + (2 * BORDER_WIDTH) +  -- leave room for border
                font_leading +                    -- plus leading below bottom line, 
                10                                -- and 5 pixels top and bottom
  
  if align_right then
    Left = Left - infowidth 
  end -- if align_right
  
  if align_bottom then
    Top = Top - infoheight 
  end -- if align_bottom
  
  WindowCreate (win, 
                Left, Top,    -- where
                infowidth,    -- width  (gap of 5 pixels per side)
                infoheight,   -- height
                4,            -- position mode: can't be 0 to 3
                2 + 4,        -- absolute location + transparent
                TRANSPARENCY_COLOUR)   -- background (transparent) colour
  
  WindowCircleOp (win, 3, -- round rectangle
        BORDER_WIDTH, BORDER_WIDTH, -BORDER_WIDTH, -BORDER_WIDTH,  -- border inset
        border_colour, 0, BORDER_WIDTH,  -- solid line
        background_colour, 0, -- solid
        5, 5)  -- diameter of ellipse

  local x = BORDER_WIDTH + WindowFontInfo (win, font_id, 6) / 2    -- start 1/2 character in 
  local y = BORDER_WIDTH + 5          -- skip border, and leave 5 pixel gap
         
  -- heading if wanted
  if heading and #heading > 0 then
    colourtext (win, heading_font_id, heading, x, y, 0, 0, capitalize)
    y = y + heading_font_height
  end -- have a heading
     
  -- show each line
  for _, v in ipairs (info) do
    colourtext (win, font_id, v, x, y, 0, 0, capitalize)
    y = y + font_height
  end -- for
  
  -- display popup window
  WindowShow (win, true)

end -- popup



- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 08 Sep 2008 05:35 AM (UTC)
Message

Output from example in the module:


- Nick Gammon

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

Posted by Larkin   (278 posts)  Bio
Date Reply #2 on Mon 08 Sep 2008 06:33 PM (UTC)
Message
What are the chances that something like this could be scripted (by you, I mean) to do ANSI sequences? The Iron Realms games now have an in-game map with colors for various terrain types that I would really love to move to a miniwindow. The ability to display a line of ANSI-coded color text in a miniwindow would be extremely useful for many things! :)

Also, how could one capture the trigger match text with all ANSI codes intact?
Top

Posted by Artrack   (8 posts)  Bio
Date Reply #3 on Mon 08 Sep 2008 08:15 PM (UTC)
Message
Oh man, if we could get the colour info for the text that would be great. I was gonna start my own miniwindow map for achaea in just a couple days and didn't even think about the colour matching.

Or, I don't know if it would even be possible, is there a way to tell MUSHclient to simply move all text received from a certain point onward, untill turned off, to miniwindow?
Top

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #4 on Mon 08 Sep 2008 09:05 PM (UTC)
Message
Both of those things are done in the mapper I wrote for Aardwolf, that displays the map in a miniwindow. You can grab a copy here:

http://www.gammon.com.au/mushclient/plugins/Aardwolf/Aardwolf_map_v2.xml

To process ANSI sequences, the simplest thing is to let MUSHclient turn the incoming text into style runs, and then display the style runs in colour, which is what the minimap plugin does. The process is explained here:

http://www.gammon.com.au/mushclient/mw_text.htm (Hint 5 near the bottom)

To move all text received to a miniwindow is simply done by two triggers (or three if you like). The map plugin does that. When the map starts to arrive it enables a second trigger that matches on "*" (everything) and copies the matching text into a table (including style runs) ready to be displayed when it notices the end of the map.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 08 Sep 2008 09:48 PM (UTC)
Message

This is what the minimap window looks like, notice the colours:


- Nick Gammon

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

Posted by Larkin   (278 posts)  Bio
Date Reply #6 on Mon 08 Sep 2008 10:32 PM (UTC)
Message
I've seen that, and I know it has colors. :)

I just didn't know if there was a way to use ANSI colors, or if you were using Aardwolf color codes to draw that map, too. (Admittedly, if something says "Aardwolf," I pretty much automatically ignore it.)

With your tips, I was able to add the colors to my IRE map window plugin in a matter of a couple minutes. Thanks!
Top

Posted by Artrack   (8 posts)  Bio
Date Reply #7 on Wed 10 Sep 2008 05:05 PM (UTC)

Amended on Wed 10 Sep 2008 05:09 PM (UTC) by Artrack

Message
I finally got a chance to try making my own map plugin and although I haven't tested if I'm doing the style runs right I'm stuck trying to find a way to stop my mapping triggers at the end of the map.

Nick, I've looked at your Aardwolf mapper and I see that <MAPEND> gets caught by the ending trigger at some point, but I don't see when that gets sent, or how.

What I've been trying to do is either find a match for "---$"
(which would happen twice with Achaea maps, it appears in just the top and bottom rows of the map). The first time that "---$" is caught would be when it just started adding this to the mapTable and the second time would be to turn off the trigger, but it doesn't happen that why. Which honestly I'm not to surprised because I'm to new to regex's. I'm at work now but now that I think of it I may have had regex'sions turned off.

Another method I tried was to match everything with "*" (regex'sions turned off) and what I got was my health/mana/etc.. getting pushed into the map and mapping trigger never turning off. On this method I added GetLineInfo(GetLineInBufferCount()) to look for the prompt but then it ended to early or not at all. The way that system worked was

type MAPGO to start it and that:
1 - turned on triggers
2 - Executed("map") --achaea map command
3 - print ( "started mapping" )

then the trigger would look for "*"
1 - add that line to the table for the overall map
2 - print ("adding ", "%1 ", "to table" ) -- my test to see if things were working
3 - check "GetLineInfo(GetLineInBufferCount()).newline" for the lack of a newline to end the trigger.

but the output would be:
adding -whatever- to map --Trigger went first???
started mapping
map -- this is the echo of the map command that executed

The trigger would go first and since the map didn't even arrive yet it would catch the lack of a new line and end everything before it started.

So I gave a lot of info and to restate what I need help with, how can I determine when the map has ended?

Thanks for the help!
Top

Posted by Larkin   (278 posts)  Bio
Date Reply #8 on Wed 10 Sep 2008 08:55 PM (UTC)
Message
I imagine that the map in Achaea looks very similar, if not perfectly identical, to the map in Lusternia. My plugin relies on the user turning on the "show map as you walk option" using CONFIG MAPVIEW ON. I made an OnConnect handler to do the initial "map" command when I login, but I haven't included that in the plugin (yet).

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>

<muclient>
<plugin
   name="TreantMap"
   author="Iasmos"
   id="93775d3ce4eba9997b61e920"
   language="Lua"
   purpose="Captures in-game map into a miniwindow view."
   date_written="2008-09-08"
   requires="4.36"
   version="1.1"
   >
</plugin>

<triggers>
  <trigger
   back_colour="8"
   enabled="y"
   group="Treant_Mapping"
   match="^\-\-\-.+? v\d+ \-\-\-+$"
   match_back_colour="y"
   match_bold="y"
   match_text_colour="y"
   name="mapstart__"
   omit_from_output="y"
   regexp="y"
   script="map_redirect"
   send_to="14"
   sequence="1000"
   text_colour="12"
  >
  </trigger>
  <trigger
   back_colour="8"
   enabled="y"
   group="Treant_Mapping"
   match="^\-\-\-.+?\-+ [\-\d]+\:[\-\d]+\:[\-\d]+ \-\-\-+$"
   match_back_colour="y"
   match_bold="y"
   match_text_colour="y"
   name="mapfinish__"
   omit_from_output="y"
   regexp="y"
   script="map_redirect"
   send_to="14"
   sequence="1000"
   text_colour="12"
  >
  </trigger>
  <trigger
   enabled="n"
   group="Treant_Mapping"
   match=".+"
   name="mapcapture__"
   omit_from_output="y"
   regexp="y"
   script="map_redirect"
   send_to="14"
   sequence="8000"
   text_colour="12"
  >
  </trigger>
</triggers>



<!--  Script  -->
<script>
<![CDATA[
if not map then
  map = {}
end

-- First line of the in-game map detected, start the capturing process
function map:start(line, styles)
  EnableTrigger("mapcapture__", true)

  -- If we haven't already created the map window, do so now
  if not self.win then
    WindowCreate("treant_map", 0, 0, 300, 300, 6, 1, ColourNameToRGB("black"))
    WindowFont("treant_map", "map", "Lucida Console", 8, false, false, false, false)

    self.width = WindowFontInfo("treant_map", "map", 7) * 47
    self.line_height = WindowFontInfo("treant_map", "map", 1)

    -- Re-create the window to fit the text using the chosen font
    WindowCreate("treant_map", 0, 0, self.width, self.line_height * 25, 6, 1, ColourNameToRGB("black"))
    WindowFont("treant_map", "map", "Lucida Console", 8, false, false, false, false)
    WindowShow("treant_map", true)

    self.win = true
  end

  WindowRectOp("treant_map", 2, 0, 0, self.width, self.line_height * 25, ColourNameToRGB("black"))

  local left = 0
  for _,s in ipairs(styles) do
    left = left + WindowText("treant_map", "map", s.text, left, 0, 0, 0, s.textcolour)
  end

  self.lines = 1
end

-- Last line of the in-game map detected, close the capturing process
function map:finish(line, styles)
  local left = 0
  for _,s in ipairs(styles) do
    left = left + WindowText("treant_map", "map", s.text, left, self.lines * self.line_height, 0, 0, s.textcolour)
  end

  EnableTrigger("mapcapture__", false)
end

-- The map being displayed, one line at a time
function map:capture(line, styles)
  local left = 0
  for _,s in ipairs(styles) do
    left = left + WindowText("treant_map", "map", s.text, left, self.lines * self.line_height, 0, 0, s.textcolour)
  end
  self.lines = self.lines + 1
end

-- map redirector
function map_redirect(name, line, wildcards, styles)
  if name == "mapstart__" then
    map:start(line, styles)
  elseif name == "mapfinish__" then
    map:finish(line, styles)
  else
    map:capture(line, styles)
  end
end
]]>
</script>
</muclient>
Top

Posted by Artrack   (8 posts)  Bio
Date Reply #9 on Thu 11 Sep 2008 05:16 AM (UTC)
Message
awsome, thanks for the help. But I have some questions,

1 How is any of the out put actually getting to the 'styles' argument
2 How anything is getting from the game and into the scripts; please understand I'm to muds and scripting. I ask this one because I do see that the triggers and using scripts, although they are not in the <send\> area and no arguemnts are being passed in.

Nick thank you for the tips too and the Hint 5, but I'm really trying to get any style info from the game and into a script but i keep getting errors.

heres an example:
Trigger: "*"
Display_Styled_Line( "%1" ) -- only displaing one line


--------- the method, yes mostly just a copy paste
function Display_Styled_Line (styles)
local left = 5
for _, v in ipairs (styles) do
left = left + WindowText (win, "font", v.text, left, 10, 0, 0, v.textcolour)
end -- for each style run
end -- Display_Styled_Line

But I get the error :
[string "Script file"]:141: bad argument #1 to 'ipairs' (table expected, got string)
Top

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #10 on Thu 11 Sep 2008 05:55 AM (UTC)
Message
You might want to check out http://www.gammon.com.au/scripting The screenshots are out of date, but the content is still valid.

Basically, the big feature that you've yet to learn about is the script file. Pressing Ctrl+Shift+H is the same as going to the Game menu and choosing Edit Script File... this notepad window edits the file that is shared between all your triggers, timers, aliases, and immediate (command line) execution. Script functions written in this file aren't specified in the Send box of the trigger dialog, but 5 boxes below it in the "Script" field. Functions in the file will have the format:

require "tprint"
function MyTrigFunc (trigName, LineTriggedOn, WildCards, Styles)
Note(trigName) -- name in the "Label" field
Note (LineTriggedOn) -- the complete line, uncoloured
tprint (WildCards) --a table with each wildcard value
tprint (Styles) --a table of tables containing each "run" (block) of coloured text. 
end


The 4th parameter Styles is only available if you're using Lua as your scripting language.
Top

Posted by Nick Gammon   Australia  (23,131 posts)  Bio   Forum Administrator
Date Reply #11 on Thu 11 Sep 2008 06:11 AM (UTC)

Amended on Thu 11 Sep 2008 06:25 AM (UTC) by Nick Gammon

Message
The styles are passed by MUSHclient if you call a script function as part of the trigger (not in send-to-script), like this:


  <trigger
   enabled="y"
   match="<MAPSTART>"
   script="map_redirect"
   omit_from_output="y"
   name="map_start"
   sequence="100"
  >
  </trigger>
  
  <trigger
   enabled="n"
   match="*"
   script="map_redirect"
   name="multi_line_map"
   omit_from_output="y"
   sequence="10"
  >
  </trigger>

  <trigger
   enabled="y"
   match="<MAPEND>"
   script="map_redirect"
   omit_from_output="y"
   name="map_end"
   sequence="5"
  >
  </trigger>



Now the script gets the styles as the fourth argument:


-- map redirector
function map_redirect (name, line, wildcards, styles)

  EnableTrigger ("multi_line_map", true)  -- capture subsequent lines

  if name == "map_start" then
    map_lines = {}
  elseif name == "map_end" then
    EnableTrigger ("multi_line_map", false)  -- no more lines to go
    Display_Map ()
  else
    table.insert (map_lines, styles)
  end -- if

end -- function map_redirect 


This example handles three cases:


  • Start (trigger name is "map_start") in which case it clears the table ready for the subsequent lines.

  • End (trigger name is "map_end") in which case it disables itself and displays the map

  • Other - it adds the styles table to the table of lines ready to be displayed later (tables can contain tables).



- Nick Gammon

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

Posted by Artrack   (8 posts)  Bio
Date Reply #12 on Thu 11 Sep 2008 06:26 AM (UTC)
Message
ahh, thanks for that. That is the part I've been missing (the 4 argument methods that triggers can send stuff too.)

Just a case where I shoulda RTFM for triggers.


Thanks a ton, it's working now :)
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.


42,754 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.