[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  #sub?

#sub?

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


Posted by Dhai   (8 posts)  [Biography] bio
Date Tue 18 Oct 2005 10:13 PM (UTC)
Message
I think there's something called '#sub' in Zmud, where I can gag the triggered text, and replace it with something else. I've tried to do this in Mushclient, with this trigger:

<triggers>
  <trigger
   enabled="y"
   group="Combat"
   keep_evaluating="y"
   match="^(\w+) springs forward and mauls your (left|right) (arm|leg)\.$"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="50"
  >
  <send>ColourNote("silver", "black", "%1: .mauled. /%2/ /%3/!")</send>
  </trigger>
</triggers>


But when I test trigger: \0AMalifuus springs forward and mauls your right leg.\0A

It matches, but I don't see the ColourNote. I'd _really_ like to be able to do this, please help!
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #1 on Wed 19 Oct 2005 02:09 AM (UTC)
Message
It's a characteristic of the way MUSHclient handles triggers and omitting, that if you omit from output it also omits any notes you do in "send to script".

However you can achieve what you want by calling a script subroutine from the trigger, like this:


<triggers>
  <trigger
   enabled="y"
   group="Combat"
   keep_evaluating="y"
   match="^(\w+) springs forward and mauls your (left|right) (arm|leg)\.$"
   omit_from_output="y"
   regexp="y"
   script="mytrigger"
   sequence="50"
  >
  </trigger>
</triggers>


And, in your script file (this example is in Lua) 

function mytrigger (name, line, wildcards)
  ColourNote("silver", "black", wildcards [1] ..
             ": .mauled. /" .. wildcards [2] .. 
             "/ /" .. wildcards [3] .. "/!")
end -- function




The difference is that rather than doing the scripting inline, it is deferred to the script file. That way you see your note.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dhai   (8 posts)  [Biography] bio
Date Reply #2 on Wed 19 Oct 2005 03:09 AM (UTC)
Message
That sort of solves my problem. The thing is, I have about 30 of these triggers, and not all of the desired substitutions can be done with wildcards. For example, I have, triggering off of:

^A hand\-sized tick with a human face leaps for your throat\.$

the substituted text of
"Ticked!"

I could obviously make a seperate function for each of these triggers but that wouldn't be efficient, and I could also get a special wildcard that's unique to each trigger (like making "hand-sized tick" a wildcard so I could have if statements to check what trigger called the sub function.

Ideally, I'd like to have something like this working:


function sub(text)
  ColourNote("silver", "black", text)
end


where in my triggers, I'd Send-To: Script, and in Send, I'd do

sub("Blah blah blah")


I'd think that would work, as you said, because it's getting deferred to the script file, but as of now I've got that first trigger I posted sending

sub("%1: .maul. /%2/ /%3/")


to the sub function I mentioned earlier, and it is doing the same thing I complained about in my first post.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Wed 19 Oct 2005 06:35 AM (UTC)
Message
Calling a sub in send-to-script doesn't really help. That effectively is still calling the script as the trigger is processed.

Putting a sub name into the "script" field defers execution of the sub until MUSHclient has finished omitting lines, so lines displayed in the script then, are still seen.

However there are ways of dealing with what you are trying to do without writing 30 functions.

For one thing, you can use named wildcards, which is particularly easy to access from Lua scripting. I have reworked my example to show how the parts of the line are named now rather than simply wildcard 1, wildcard 2 etc.

The script could then test to see if a particular name exists (ie. is not nil), and adjust its display accordingly.

Also, the script can see which trigger called it, that is the first argument, the "name" argument. By giving each trigger a different label (name) then the script can conditionally handle different types of triggers.


<triggers>
  <trigger
   enabled="y"
   group="Combat"
   keep_evaluating="y"
   match="^(?P&lt;who&gt;\w+) springs forward and mauls your (?P&lt;which&gt;left|right) (?P&lt;part&gt;arm|leg)\.$"
   omit_from_output="y"
   regexp="y"
   script="mytrigger"
   sequence="50"
  >
  </trigger>
</triggers>



Revised script using names rather than numbers

function mytrigger (name, line, wildcards)

  ColourNote("silver", "black", wildcards.who ..
             ": .mauled. /" .. wildcards.which .. 
             "/ /" .. wildcards.part .. "/!")

end -- function

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dhai   (8 posts)  [Biography] bio
Date Reply #4 on Wed 19 Oct 2005 02:00 PM (UTC)
Message
Ah, yes. Thank you. It'll take a bit more work than I was expecting, but it certainly solves my problem.
[Go to top] top

Posted by Dragish   USA  (10 posts)  [Biography] bio
Date Reply #5 on Thu 10 Nov 2005 12:53 AM (UTC)
Message
i want to do roughly the same thing except i dont have any wildcard in the line i want to replace. i was thinking of setting it up in the following manner:

triggers>
<trigger
enabled="y"
group="Combat"
keep_evaluating="y"
match="^a sprig of eliotropia$"
omit_from_output="y"
regexp="y"
script="mytrigger"
sequence="50"
>
</trigger>
</triggers>

i want it to output
a sprig of eliotropia +8

im just not sure how to set up the script to out put it.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Thu 10 Nov 2005 05:00 AM (UTC)
Message
Well a script to simply send static stuff is really simple:


function mytrigger (name, line, wildcards)
  ColourNote("silver", "black", "a sprig of eliotropia +8")
end -- function


However as you are echoing back most of what you received, you can get that from wildcard 0, the whole matching line:


function mytrigger (name, line, wildcards, styles)
  ColourNote("silver", "black", wildcards [0] ..  " +8")
end -- function


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Thu 10 Nov 2005 05:32 AM (UTC)
Message
Now if you wanted to do a lot of these, and I assume you do, rather than writing a different script function for each one, you can have a single one, and have it look up the addition in a table. In this case we use the description as the key for matching in the table.


extras = {

  ["a sprig of eliotropia"] = "+8",
  ["a leaf of sunflower"] = "+16",
  ["a bunch of tulips"] = "+4",

}
 
function mytrigger (name, line, wildcards, styles)

  local extra = extras [line] -- table lookup

  -- append extra stuff if found in table
 
  line = line .. " " .. extra or ""
  
  ColourNote("silver", "black", line)
end -- function



Now each trigger can call the same script function, and inside the function it works out what to append to the line.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Dragish   USA  (10 posts)  [Biography] bio
Date Reply #8 on Fri 11 Nov 2005 04:52 AM (UTC)
Message
i tried setting it up as you said except i get this error message

There was a problem in script file "D:\Program Files\games\MUSHclient\scripts\sprigs.lua":

The trigger subroutine named "sprig" could not be found.
The trigger (sprig) subroutine named "sprig" could not be found.

i copied and pasted it exactly

i only got that when it was working off a trigger, but when there was no trigger calling it, it didnt work
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #9 on Fri 11 Nov 2005 10:32 AM (UTC)
Message
That means you copied it to a wrong place. If your trigger is inside the world (not in a plugin), then the function must be inside the script file attached to that world in the Configuration->Scripting dialogue. And the function must have the same name as the one you put in the Script field of your trigger.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #10 on Fri 11 Nov 2005 07:42 PM (UTC)
Message
The trigger you pasted above calls a function "mytrigger" but the message you pasted says it can't find "sprig". You must have changed the trigger.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] 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.


23,406 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]