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 ➜ Suggestions ➜ Multi-line triggers? Why so special?

Multi-line triggers? Why so special?

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


Posted by Nickpick   (24 posts)  Bio
Date Sun 23 Jul 2006 04:55 PM (UTC)
Message
My question is fairly straight forward:

Why are the muti-line triggers so limited in features?

We can change the colour of the line and even worse, we can't omit the multi-lines from the output, which is a pain.

My currect problem is removing the line which is clearly a bit of spam as well as it's following prompt line. Barely a problem with a little script and it's been solved, but why can't it go simpler?
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 24 Jul 2006 12:30 AM (UTC)
Message
It is important to note that multi-line triggers are handled somewhat differently internally to single-line triggers.

A single-line trigger is basically the last thing that arrived from the MUD.

A multi-line trigger is implemented by saving the most recent 200 lines in a special area, however world.Note lines, and command input is not saved. This is so that something like this will still match:


You stand in mud all the way up to your thighs and it's not too 
comfortable since you are used to a somewhat different environment.
north (command)
The sewer leads to the north of here. In the middle you can just make
Timer fired! (world.Note)
out an enormous drainpipe leading down.


In this example the command and the note are not considered for multi-line triggers. However attempting to colour such a match (or omit it) would be quite tedious internally.

However as this sort of question comes up fairly frequently, version 3.76 of MUSHclient will feature a new script function: DeleteLines.

This will allow for the scripted deletion of the last N lines from the output window.

- Nick Gammon

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

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #2 on Mon 24 Jul 2006 12:10 PM (UTC)
Message
Awsome, I will have a ton of usage for this new feature, as I have had to break my "Multi-Line" triggers into

'^(TRIGGER1|TRIGGER2)$' style triggers

so that I can color, or omit, or even parse things in the twisted ways I get them to function.

In addition I think that a function is needed for
http://www.gammon.com.au/forum/bbshowpost.php?bbsubject_id=7218&page=999999

Where it saves the ascii characters or colours if you will of the matched item, which I don't think would be too terribly difficult, just get the start and end of the match and from those positions look ahead and behind for all nonprinting characters (i.e. non characters, and non spaces) then also concat's that into the matched "variable" (used loosly as the place the match is stored to be refered to by '%X' or wildcards[x] in LUA" then that would allow VERY easy manipulation of lines, prompts, anything for that matter that happens to have color in it.

Thanks,
Onoitsu2
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Mon 24 Jul 2006 09:18 PM (UTC)
Message
For a one-line trigger you can already do this. The Lua trigger handler is passed a 4th argument which is a list of all style runs in that line, and what colours each one is.

For the multi-line situation (or if you are not using Lua), before omitting the line(s), you can get their style runs (with GetLineInfo and GetStyleInfo).

- Nick Gammon

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

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #4 on Tue 25 Jul 2006 11:00 AM (UTC)

Amended on Tue 25 Jul 2006 09:33 PM (UTC) by Nick Gammon

Message
I think you would have to elaborate using an example on that one Nick, as those 2 commands are as understandable as a blind man trying to read (non-braille obviously :P)

I play on Aardwolf, and items and things use MANY MANY colors, standard ANSI, but something may be inverse every other letter and each letter a diff color, so there can be quite a few ascii color codes embedded in nearly every line.

Here is what have so far...
Line 735 used
Line 735 = (Gossip) Aboltite waves his hands about in grand gestures as he casts, 'SUMMON DOUBLE!'



string = "\"white\", \"black\", \"\"" 
for  i =1, GetLineInfo(735, 11) do
string = string ..
         ", \""..
         RGBColourToName(world.GetStyleInfo (735, i,14)) ..
         "\", \"" ..
         RGBColourToName(world.GetStyleInfo (735, i,15)) ..
         "\", \"" ..
         Replace(world.GetStyleInfo (735, i,1),"\"","\\\"",true) ..
         "\""
end
Note(string)
ColourNote("white", "black", "", "cyan", 
           "black", "(Gossip) ", "white", 
           "black", "Aboltite waves his hands about in grand gestures as he casts, \"", 
           "lime", "black", "SUMMON DOUBLE!", 
           "white", "black", "\"", "silver", "black", "")
)


The stuff in the 2nd ColourNote is the exact copy from what is in the string variable, yet the first ColourNote fails to function I get an error...

[string "Immediate"]:5: bad argument #3 to `ColourNote' (string expected, got no value)
stack traceback:
	[C]: in function `ColourNote'
	[string "Immediate"]:5: in main chunk


Thanks,
Onoitsu2

Reformatted by Nick
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 25 Jul 2006 09:38 PM (UTC)
Message
It's not really an exact copy. You have turned it all into one argument. For example this works:


ColourNote ("white", "blue", "hello, world")


This doesn't:


ColourNote ('"white", "blue", "hello, world"')


In the second example I have turned everything into a single argument, with quotes inside it. That is not how ColourNote works.

As you are clearly trying to build up the line "on the fly" from the style runs, you might want to use this method instead:


str = {}

-- first one
table.insert (str, "white")
table.insert (str, "blue")
table.insert (str, "hello")

-- second one

table.insert (str, "gray")
table.insert (str, "green")
table.insert (str, ", world")

-- display it

ColourNote (unpack (str))


This gradually builds up colour names and text into a table (str) and then calls ColourNote using unpack, that converts a table into a run of arguments. That works.

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #6 on Tue 25 Jul 2006 09:44 PM (UTC)

Amended on Tue 25 Jul 2006 09:46 PM (UTC) by Nick Gammon

Message
In your case it could look like this:



line = 735 -- for testing

str = {}

for  i =1, GetLineInfo(line, 11) do
  table.insert (str, RGBColourToName(GetStyleInfo (line, i,14)))
  table.insert (str, RGBColourToName(GetStyleInfo (line, i,15)))
  table.insert (str, GetStyleInfo (line, i,1))
end

ColourNote (unpack (str))


- Nick Gammon

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

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #7 on Wed 26 Jul 2006 11:39 AM (UTC)
Message
What I have so far... and it works :) may be a little unothorodox but functions well.
That unpack command is located no where in the MUSHclient help file, nor in the SCITE helpfile listing of LUA info and commands, so this probably could be more wasily done using the method you show there Nick, and have a more expansive color scheme as you can append/prepend in more colors than just ANSI set ones.

PART 1 OF 2

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE muclient>
<!-- Saved on Wednesday, July 26, 2006, 3:12 AM -->
<!-- MuClient version 3.74 -->

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

<muclient>
<plugin
   name="RecreateANSI_LUA"
   author="Onoitsu2"
   id="333bc2186715366b0e0c5207"
   language="Lua"
   purpose="Allows users to retain ANSI formatting and add text before or after the line matched"
   date_written="2006-07-26 03:10:43"
   requires="3.70"
   version="1.0"
   >
<description trim="n">
<![CDATA[
RecreateANSI_LUA Helpfile
-------------------
TRIGGER MUST OMIT FROM OUTPUT TO PREVENT DUPLICATION
Add styles to trigger function definition,
i.e.: function NAME(sName,sLine,wildcards,STYLES)
and then pass the variable into the recreateansi function
world.CallPlugin("333bc2186715366b0e0c5207", "recreateansi", STYLES,"text_to_add","before/after","fcolor","bcolor","bold(true/false)")
You can set this to a variable or simply pass the function itself into the AnsiNote()
function. i.e.: AnsiNote(world.CallPlugin("333bc2186715366b0e0c5207", "recreateansi", STYLES,"text_to_add","before/after","fcolor","bcolor","bold(true/false)"))

Breakdown
-----------
AnsiNote(world.CallPlugin("333bc2186715366b0e0c5207", "recreateansi", STYLES,"text_to_add","before/after","fcolor","bcolor","bold(true/false)"))

STYLES = variable named in trigger function function x(sName,sLine,wildcards,STYLES)
---
"text_to_add" = what to append/prepend to the matched line (can be nearly anything that has [return] value convertable to string, i.e. ,"Blah" .. variable, OR
				another function that will give the return value)
---
"before/after" = sets position of the "text_to_add" - "Before" or "After", defaults to "After" if "" (CASE INSENSITIVE)
---
"fcolor" = text color of "text_to_add" - valid values "Black","Red","Green","Yellow","Blue","Magenta","Cyan","White" defaults to "White" if "" (CASE INSENSITIVE)
---
"bcolor" = back color of "text_to_add" - valid values "Black","Red","Green","Yellow","Blue","Magenta","Cyan","White" defaults to "Black" if "" (CASE INSENSITIVE)
---
"bold(true/false)") = sets bold or non-bold appended/prepended text - valid values "True","False" defaults to "False" if "" (CASE INSENSITIVE)

]]>
</description>
</plugin>


<!--  Get our standard constants -->

<include name="constants.lua"/>

<!--  Script  -->


<script>
<![CDATA[

function OnPluginInstall()
OnHelp()
end

function OnHelp ()
  world.Note (world.GetPluginInfo (world.GetPluginID (), 3))
end

function recreateansi(linestyles,addtext,beforeafter,fcolor,bcolor,bold)
if addtext == nil or addtext == "" then addtext = "" end
if beforeafter == nil or beforeafter == "" then beforeafter = "after" end
if fcolor == nil or fcolor == "" then fcolor = "white" end
if bcolor == nil or bcolor == "" then bcolor = "black" end
if bold == nil or bold == "" or (string.lower(bold) ~= "true" and string.lower(bold) ~= "false") then
bold = 22
elseif string.lower(bold) == "true" then
bold = 1
end
created = ""
styles = table.getn(linestyles)
for style = 1, styles do
--	Note(linestyles[style]["text"])
--	Note(linestyles[style]["textcolour"])
--	Note(linestyles[style]["backcolour"])
--	Note(linestyles[style]["style"])
created = created .. ransi(linestyles[style]) .. linestyles[style]["text"]
end -- for
  if string.lower(fcolor) == "black" then
  fcolor = 30
  elseif string.lower(fcolor) == "red" then
  fcolor = 31
  elseif string.lower(fcolor) == "green" then
  fcolor = 32
  elseif string.lower(fcolor) == "yellow" then
  fcolor = 33
  elseif string.lower(fcolor) == "blue" then
  fcolor = 34
  elseif string.lower(fcolor) == "magenta" then
  fcolor = 35
  elseif string.lower(fcolor) == "cyan" then
  fcolor = 36
  elseif string.lower(fcolor) == "white" then
  fcolor = 37
  else
  fcolor = 37
  end -- fcolor
  if string.lower(bcolor) == "black" then
  bcolor = 40
  elseif string.lower(bcolor) == "red" then
  bcolor = 41
  elseif string.lower(bcolor) == "green" then
  bcolor = 42
  elseif string.lower(bcolor) == "yellow" then
  bcolor = 43
  elseif string.lower(bcolor) == "blue" then
  bcolor = 44
  elseif string.lower(bcolor) == "magenta" then
  bcolor = 45
  elseif string.lower(bcolor) == "cyan" then
  bcolor = 46
  elseif string.lower(bcolor) == "white" then
  bcolor = 47
  else
  bcolor = 40
  end -- bcolor

if string.lower(beforeafter) == "before" then
  return ANSI(bold,fcolor,bcolor) .. addtext .. created
else
  return created .. ANSI(bold,fcolor,bcolor) .. addtext
end -- before after check
end -- recreateansi
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #8 on Wed 26 Jul 2006 11:40 AM (UTC)
Message
PART 2 OF 2


function ransi(stylenum)
local flagb = nil
local fcolor = nil
local bcolor = nil
for fore = 1, 8 do
 if stylenum["style"] == 1 then
   flagb = 1
 else
   flagb = 0
 end -- if
  if stylenum["textcolour"] == GetBoldColour(fore) then
   if fore == 1 then
	fcolor = 30
   end
   if fore == 2 then
	fcolor = 31
   end
   if fore == 3 then
	fcolor = 32
   end
   if fore == 4 then
	fcolor = 33
   end
   if fore == 5 then
	fcolor = 34
   end
   if fore == 6 then
	fcolor = 35
   end
   if fore == 7 then
	fcolor = 36
   end
   if fore == 8 then
	fcolor = 37
   end
  elseif stylenum["textcolour"] == GetNormalColour(fore) then
   if fore == 1 then
	fcolor = 30
   end
   if fore == 2 then
	fcolor = 31
   end
   if fore == 3 then
	fcolor = 32
   end
   if fore == 4 then
	fcolor = 33
   end
   if fore == 5 then
	fcolor = 34
   end
   if fore == 6 then
	fcolor = 35
   end
   if fore == 7 then
	fcolor = 36
   end
   if fore == 8 then
	fcolor = 37
   end
  end -- fore
end -- for

for back = 1, 8 do
  if stylenum["backcolour"] == GetBoldColour(back) then
   if back == 1 then
	bcolor = 40
   end
   if back == 2 then
	bcolor = 41
   end
   if back == 3 then
	bcolor = 42
   end
   if back == 4 then
	bcolor = 43
   end
   if back == 5 then
	bcolor = 44
   end
   if back == 6 then
	bcolor = 45
   end
   if back == 7 then
	bcolor = 46
   end
   if back == 8 then
	bcolor = 47
   end
  elseif stylenum["backcolour"] == GetNormalColour(back) then
   if back == 1 then
	bcolor = 40
   end
   if back == 2 then
	bcolor = 41
   end
   if back == 3 then
	bcolor = 42
   end
   if back == 4 then
	bcolor = 43
   end
   if back == 5 then
	bcolor = 44
   end
   if back == 6 then
	bcolor = 45
   end
   if back == 7 then
	bcolor = 46
   end
   if back == 8 then
	bcolor = 47
   end
  end -- end back
end -- for

if flagb ~= nil then
 if flagb == 1 then
  if fcolor ~= nil then
   if bcolor ~= nil then
    return ANSI(1,fcolor,bcolor)
   end
  end
 else
  if fcolor ~= nil then
   if bcolor ~= nil then
    return ANSI(22,fcolor,bcolor)
   end
  end
 end
end
return ""
end -- ransi
]]>
</script>
</muclient>
Top

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #9 on Wed 26 Jul 2006 12:16 PM (UTC)
Message
Now that I know about the unpack command I have signifigantly shortened this ...


function recreateansi(linestyles,addtext,beforeafter,fcolor,bcolor)
if addtext == nil or addtext == "" then addtext = "" end
if beforeafter == nil or beforeafter == "" then beforeafter = "after" end
if fcolor == nil or fcolor == "" then fcolor = "white" end
if bcolor == nil or bcolor == "" then bcolor = "black" end
local str = {}
styles = table.getn(linestyles)
for style = 1, styles do
  table.insert (str, RGBColourToName(linestyles[style]["textcolour"]))
  table.insert (str, RGBColourToName(linestyles[style]["backcolour"]))
  table.insert (str, linestyles[style]["text"])
end -- for

if string.lower(beforeafter) == "before" then
table.insert (str, 1, fcolor)
table.insert (str, 2, bcolor)
table.insert (str, 3, addtext)
ColourNote (unpack (str))
else
table.insert (str, fcolor)
table.insert (str, bcolor)
table.insert (str, addtext)
ColourNote (unpack (str))
end
end -- recreateansi


can be called via


recreateansi(STYLES,TEXT,after/before,fcolor,bcolor)


example:

<trigger
enabled="n"
expand_variables="y"
group="AlignReport"
ignore_case="y"
keep_evaluating="y"
match="^Your alignment is: (.*?).$"
omit_from_output="y"
regexp="y"
repeat="y"
script="AlignEvaluate"
sequence="50"
>
</trigger>

function AlignEvaluate(sName,sLine,wildcards,STYLES)
recreateansi(STYLES,"BLAH","after","white","orange")
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #10 on Wed 26 Jul 2006 10:24 PM (UTC)

Amended on Wed 26 Jul 2006 10:25 PM (UTC) by Nick Gammon

Message
OK, good. For future reference, you may want to consider using Lua tables rather than all those lengthy IF statements. For example, instead of:


 if string.lower(fcolor) == "black" then
    fcolor = 30
  elseif string.lower(fcolor) == "red" then
    fcolor = 31
  elseif string.lower(fcolor) == "green" then
    fcolor = 32
  elseif string.lower(fcolor) == "yellow" then
    fcolor = 33
  elseif string.lower(fcolor) == "blue" then
    fcolor = 34
  elseif string.lower(fcolor) == "magenta" then
    fcolor = 35
  elseif string.lower(fcolor) == "cyan" then
    fcolor = 36
  elseif string.lower(fcolor) == "white" then
    fcolor = 37
  else
   fcolor = 37
  end -- fcolor
  if string.lower(bcolor) == "black" then
    bcolor = 40
  elseif string.lower(bcolor) == "red" then
    bcolor = 41
  elseif string.lower(bcolor) == "green" then
    bcolor = 42
  elseif string.lower(bcolor) == "yellow" then
    bcolor = 43
  elseif string.lower(bcolor) == "blue" then
    bcolor = 44
  elseif string.lower(bcolor) == "magenta" then
    bcolor = 45
  elseif string.lower(bcolor) == "cyan" then
    bcolor = 46
  elseif string.lower(bcolor) == "white" then
    bcolor = 47
  else
   bcolor = 40
  end -- bcolor



use:


colours = {
  black = 30, red = 31,     green = 32, yellow = 33,
  blue = 34,  magenta = 35, cyan = 36,  white = 37 
  }

fcolor =  colours [string.lower (fcolor)] or 37
bcolor = (colours [string.lower (bcolor)] + 10) or 40




Much easier to read, don't you think?

- Nick Gammon

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

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #11 on Thu 27 Jul 2006 05:37 AM (UTC)
Message
Quote:

That unpack command is located no where in the MUSHclient help file ...


Actually it is here:

http://www.gammon.com.au/scripts/doc.php?general=lua_base

That exact page is also in the MUSHclient help file.

- Nick Gammon

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

Posted by Onoitsu2   USA  (248 posts)  Bio
Date Reply #12 on Thu 27 Jul 2006 12:03 PM (UTC)
Message
As far as tables are concerned I try to avoid them like the plague, as I want people using ANY programming language for plugins to have as little overhead in decyphering and converting to say VBscript for example. I have learned all I have from simplistic (nothing fancy) programming examples, and also feel that if someone wants to learn LUA and has one of these other languages MUSHclient supports under their belt, then using these methods is the "standard" of most languages (I use standard VERY loosely, but VBscript, Jscript, and others DO use this a lot in themselves, even batch scripts)

When I program in C++, I do know it is object related, but I still try to use the straight forward practiced usage of a batch script, WITH object support.

And the tables may be cleaner and easier to read, but come on, if you were new to LUA and looked at that, but knew another language you would probably go "HUH?!", then have to track down the table definition, then try to find out what the heck is going on there, as not all languages support "NAMED" array indexing, which is all a table is, is a fancy array.
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.


35,124 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.