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, 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 ➜ General ➜ Filtering the items in trigger/timer/alias/variable lists

Filtering the items in trigger/timer/alias/variable lists

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


Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Sat 17 Jun 2006 04:08 AM (UTC)
Message
Shadowfyr made a suggestion in this thread: http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=6468

Basically it was to have a method of filtering the entries shown in trigger (etc.) lists in the MUSHclient GUI.

I have added that capability into version 3.75. It is especially intended for users that have hundreds of items, and under some circumstances it can be tedious to locate a particular item (eg. a single trigger that has a missing subroutine in the script file).

For example, he wanted to find triggers that did a "send to script". He suggested some sort of dialog box with lots of options on it, but I couldn't see how that could work in more complex examples (eg. send to script *and* enabled) so I thought it would be easier if you could simply script the condition.

How it works is you provide a filter function written in Lua (regardless of whatever your scripting language for your main world file is, if any). This is provided the key for each item (eg. trigger name). You then do GetTriggerInfo (GetAliasInfo etc.) to find details about that item and decide whether or not to show it. For example, to find all triggers that did a "send to script" ...


function filter (s)
  return GetTriggerInfo (s, 15) == 12 
end -- filter


This returns true if "send to" field is 12 (script).

Now you can make more complex checks by using a longer "if" statement. For example, this will show items which are send to script AND enabled:


function filter (s)
  return GetTriggerInfo (s, 15) == 12 and  -- send to script
         GetTriggerInfo (s, 8)  -- enabled
end -- filter


In the variables list you might filter out by name or content. Here is an example of only displaying MXP variables:


function filter (s)
  return string.find (s, "^mxp_") ~= nil
end -- filter


Another example, this filters out so that only aliases which had a bad script name are shown:


function filter (s)
  return not GetAliasInfo (s, 27) and  -- script not found
             GetAliasInfo (s, 3) ~= "" -- but name given
end -- filter


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #1 on Sat 17 Jun 2006 05:03 AM (UTC)

Amended on Sat 17 Jun 2006 05:15 AM (UTC) by Nick Gammon

Message
Below is a fancier example. This uses utils.listbox to let you choose the type of filtering on-the-fly. How this works is that the listbox pops up as soon as filtering is enabled, and selects the correct filter function.


function send_to_script (s)
  return GetTriggerInfo (s, 15) == 12 and -- send to script
         GetTriggerInfo (s, 8)            -- enabled
end -- send_to_script 

function enabled (s)
  return GetTriggerInfo (s, 8)  -- enabled
end -- enabled 

function badscript (s)
  return not GetTriggerInfo (s, 34) and  -- script not found
             GetTriggerInfo (s, 4) ~= "" -- but name given
end -- badscript 

function temporary (s)
  return GetTriggerInfo (s, 23)  -- temporary
end -- temporary 

function matched (s)
  return GetTriggerInfo (s, 21) > 0 -- match count
end -- matched 

-- if they cancel, show everything
function everything (s) 
  return true
end -- everything 

-- choose which function to use
result = utils.listbox ("Choose type of filtering", "Triggers",
           { 
           send_to_script = "Send to script and enabled",
           enabled = "Enabled items",
           badscript = "Script name not found",
           temporary = "Temporary triggers",
           matched = "Ones that matched something",
           },
           "badscript") -- default

-- use that function
filter = _G [result] or everything


- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,072 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 11 Jul 2006 12:49 AM (UTC)
Message
An example of filtering triggers/timers/aliases along the above lines is provided in the file Example_Filters.lua which ships with MUSHclient.

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


8,611 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.