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 ➜ General ➜ Help with 'omit' and 'Note'

Help with 'omit' and 'Note'

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


Pages: 1  2 

Posted by Mpa   (9 posts)  Bio
Date Reply #15 on Thu 24 Aug 2006 06:06 PM (UTC)
Message
Another problem that I encountered. I basically have to change all triggers which text I want to replace to execute script "DeferNote". For one thing, some triggers are calling their own script, for another, there's so damn many of them.

An example of my trigger :

<triggers>
<trigger
enabled="y"
group="Asthma"
match="You feel a tightening sensation grow in your lungs."
omit_from_output="y"
regexp="n"
send_to="10"
sequence="100"
>
<send>afflict asthma</send>
</trigger>
</triggers>

<aliases>
<alias
script="afflict"
match="afflict *"
enabled="y"
send_to="10"
sequence="100"
>
</alias>
</aliases>

The reason why I use an alias is because it makes it easier to test stuff, easier to create a new trigger and in the trigger dialogue box, you can sort triggers according to their "Send" box.

Is there a way to omit the original output and replace it with colour.note called from an alias ?
That way, changing one alias / script would change all one or two hundreds affliction triggers that rely on this alias.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #16 on Thu 24 Aug 2006 09:11 PM (UTC)

Amended on Thu 24 Aug 2006 09:39 PM (UTC) by Nick Gammon

Message
Let's look at the technique first - to defer an alias we simply store up what the alias is to do, and then do it later, like this:


deferred_aliases = {}  -- table of things to be done

-- do a deferred alias - called from a trigger
function DeferAlias (name, line, wildcards)

local k, v

  for k, v in ipairs (deferred_aliases) do
    world.Execute (v)
  end -- for looop

  deferred_aliases = {}  -- done with table

end -- function DeferAlias 

-- add a deferred alias to the table
function defer (what)
  table.insert (deferred_aliases, what)
end -- function defer 


This is similar code to the previous example, but now we are calling world.Execute to execute (ie. process the command) that we previously saved. Now the trigger and alias look like this:


<triggers>
  <trigger
   enabled="y"
   match="You feel a tightening sensation grow in your lungs."
   omit_from_output="y"
   script="DeferAlias"
   send_to="12"
   sequence="100"
  >
  <send>defer ("afflict asthma")</send>
  </trigger>
</triggers>


<aliases>
  <alias
   match="afflict *"
   enabled="y"
   send_to="12"
   sequence="100"
  >
  <send>ColourNote ("black", "white", "Afflict : ", 
            "white", "red", string.upper ("%1"))</send>
  </alias>
</aliases>



Now the trigger adds to the list of things to be done "afflict asthma" by calling the defer function.

The defer function adds the item to a queue (list) and then the DeferAlias function called at the end of trigger processing calls world.Execute to send that to the MUSHclient command processor, which will catch the alias.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #17 on Thu 24 Aug 2006 09:17 PM (UTC)

Amended on Thu 24 Aug 2006 09:20 PM (UTC) by Nick Gammon

Message
Quote:

Is there a way to omit the original output and replace it with colour.note called from an alias ?
That way, changing one alias / script would change all one or two hundreds affliction triggers that rely on this alia


[EDIT] My original idea didn't work. :)

I tried sending all of the messages to an alias, and then calling DeferNote from the alias, but there is a timing problem there. The alias did its note, but then the trigger omitted it from output.

OK, we need another way ...

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #18 on Thu 24 Aug 2006 09:37 PM (UTC)

Amended on Thu 24 Aug 2006 09:39 PM (UTC) by Nick Gammon

Message
You can automate large-scale trigger fixups, as triggers can be accessed from inside scripts. I made a script in the Immediate window to do this (although for safety you might put it into the script file).


function fix_one_trigger (name)

  if GetTriggerInfo (name, 6) -- omit from output
  and GetTriggerInfo (name, 15) == 10 -- send to execute
  and GetTriggerInfo (name, 4) == "" -- no script function
  then
    -- make "send" field into 'defer "<whatever>"'
    SetTriggerOption (name, "send", 
           'defer ("' .. GetTriggerInfo (name, 2) .. '")')
    -- make "send_to" to be "execute"
    SetTriggerOption (name, "send_to", "12")
    -- make "script" to be "DeferAlias"
    SetTriggerOption (name, "script", "DeferAlias")
    Note ("Fixed trigger " .. name)
  end -- if

end -- function fix_one_trigger


-- fix up all triggers
function fix_up_triggers ()

local k, v

  for k, v in GetTriggerList () do
    fix_one_trigger (v)
  end -- for

end -- function fix_up_triggers 

fix_up_triggers ()



What this does is:


  • Use GetTriggerList to find all triggers
  • For each one, call fix_one_trigger passing it the name of the trigger
  • If the trigger meets the requirements (you can add more of your own):

    • It is omitting from output
    • It is doing a "send to execute"
    • It has no script function yet

  • Then it changes it to "defer <whatever it was sending>"
  • Sends to script rather than execute
  • Puts the function name "DeferAlias" into the script name field


The only big problem this one would have is for multi-line stuff (eg. two aliases) if you are using them.

In that case modify the script to break the "send" text into lines and do a "defer" on each line.

You might put a test in the script for a newline inside the send text, and at least do a warning if you find it.

Warning - back up your world file before you play with this idea, you will have trouble reverting your triggers once you run the script.

- Nick Gammon

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

Posted by Mpa   (9 posts)  Bio
Date Reply #19 on Sun 27 Aug 2006 02:39 AM (UTC)
Message
Hehe, I did try calling the DeferNote through an alias which is executed through world(execute) in the trigger.

I am aware of the settrigger functions, I just I dont like having triggers directly calling a script function. But I guess there's no way around it. A big thank you to Nick, for taking the time and energy in trying to solve this problem.

PS.
Maybe in the future this behaviour could be changed to make it easier, more intuitive ?
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.


63,801 views.

This is page 2, subject is 2 pages long:  [Previous page]  1  2 

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.