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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Working with the line

Working with the line

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


Pages: 1  2 3  

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #15 on Fri 09 Sep 2016 09:09 PM (UTC)
Message
You just put:


dslpnp.statusbar.promptHandler


Look at some of the examples. The client supplies the arguments automatically in the order I gave.

You are giving the name of the function to call. You aren't writing a line of code to call it.

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #16 on Sat 10 Sep 2016 11:30 AM (UTC)
Message
Nick Gammon said:

You just put:


dslpnp.statusbar.promptHandler


Look at some of the examples. The client supplies the arguments automatically in the order I gave.

You are giving the name of the function to call. You aren't writing a line of code to call it.


OK. That's what I figured.

Now, strangely, on the nospoof thing, this is what I made for my script file:


pnp.nospoof = dslpnp.nospoof or {}

function pnp.nospoof.gather(name, line, wildcards, styles)
    local noSpoof = string.gsub (wildcards[1], "[%^%$%(%)%%%.%[%]%*%+%-%?]", "%%%1")
    
    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 
    
    Note("")
end


I saved it in MUSHclient\Scripts\pnp_nospoof.lua

I set the trigger as follows:

Regex:

([([\w'\-\s\d]+)\(#(\d+)\)(?:\{(\w+)\})?(?:<\-\(#([\d-]+)\))?(?:,(\w+))?]\s)

* Still having some issues with this matching every single nospoof instance.

Enabled: Checked
Omit from output: Checked
Keep evaluating: Checked
Regular expression: Checked

Send to: World
Squence: 100
Label: triNoSpoofCapture
Script: pnp.nospoof.gather
Group: global

The error I get upon closing the trigger is:
Quote:

You have not specified a script file name:

The trigger (triNoSpoofCapture) subroutine named "pnp.nospoof.gather" could not be found.


The XML:

<triggers>
  <trigger
   enabled="y"
   group="global"
   keep_evaluating="y"
   match="([([\w'\-\s\d]+)\(#(\d+)\)(?:\{(\w+)\})?(?:&lt;\-\(#([\d-]+)\))?(?:,(\w+))?]\s)"
   name="triNoSpoofCapture"
   omit_from_output="y"
   regexp="y"
   script="pnp.nospoof.gather"
   sequence="100"
  >
  </trigger>
</triggers>
[Go to top] top

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #17 on Fri 16 Sep 2016 12:46 PM (UTC)
Message
Right now, I still haven't been able to figure out the error. I'd really like to begin working on more scripts for MUSHclient, but this is part of doing that.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #18 on Sat 17 Sep 2016 02:30 AM (UTC)
Message
Quote:

The trigger (triNoSpoofCapture) subroutine named "pnp.nospoof.gather" could not be found.


Well, is it there or not? You should be able to prove that by typing at the command line (assuming you set "/" to be the scripting prefix):


/ print (type (pnp.nospoof.gather))


If you don't see "function" printed then something is wrong in the way you are setting up your script.

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #19 on Sat 17 Sep 2016 04:12 AM (UTC)
Message
So... funny story.

I didn't realize I had to "load" the script in. For some reason I assumed scripts in a certain folder would auto-load in. Whoops.

Worse, I assumed / was the default Lua. Nope, there isn't one. So, while I tried to troubleshoot using Lua from the command-line, it didn't work.

Now I know that I have to load scripts in (with all the options that go along with it.

Unfortunately, having some minor issues with my regex pattern not working 100%.

Thanks for the help!
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #20 on Sat 17 Sep 2016 08:49 PM (UTC)
Message
Quote:

Worse, I assumed / was the default Lua. Nope, there isn't one.


Yes, the command line is, by default, sent to the MUD. The scripting prefix changes that to send to the current script engine.

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #21 on Wed 21 Sep 2016 01:05 AM (UTC)

Amended on Wed 21 Sep 2016 02:21 AM (UTC) by Nick Gammon

Message
In terms of matching the line and pulling things out of it in the MU* I am testing on, everything is almost perfect (Still working through issues on the prompt replacement for the MUD).

Back to the MU*, the following lines are still not being edited out by the gsub. However, since the ultimate goal is to be able to pull the nospoof apart for data, I really need to better understand the gsub so that I can grab information from it for the various nospoof patterns that I need to parse.

Quote:

[bbpocket(#21){Core}<-(#20)] (New BB message (4/46) posted to 'IC Requests' by Jessamyn: Looking for a knight)
[SGP - Main Globals(#6){Core}<-(#9256)] Ceel goes OOC.


One of the other things I've noticed is that all of the replaced lines are offset by a single character. Indent paragraphs isn't checked.

Trigger:

<triggers>
  <trigger
   custom_colour="2"
   enabled="y"
   group="Global"
   keep_evaluating="y"
   match="(\[([^\]]*)\])"
   name="triNoSpoofCapture"
   omit_from_output="y"
   regexp="y"
   script="pnp.nospoof.gather"
   sequence="100"
  >
  </trigger>
</triggers>


Script:

pnp = pnp or {}
pnp.nospoof = pnp.nospoof or {}

function pnp.nospoof.gather(name, line, wildcards, styles)
    --print(wildcards[1])
    local noSpoof = string.gsub(wildcards[1], "[%^%$%(%)%%%.%{%}%[%]%*%+%-%?]", "%%%1")
    noSpoof = string.gsub(noSpoof, "^%s", "")
    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 
    
    Note()
end


So my question is two-fold:

1) What's with the unnecessary indent?

2) Why aren't the quoted lines matching the gsub?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #22 on Wed 21 Sep 2016 02:32 AM (UTC)

Amended on Wed 21 Sep 2016 02:33 AM (UTC) by Nick Gammon

Message
Quote:

1) What's with the unnecessary indent?


The indent is because you don't get rid of the space after the spoof stuff. If you tprint the style runs you see this:


1:
  "textcolour"=8454143
  "backcolour"=0
  "length"=34
  "style"=0
  "text"="[Barrabus(#9443){Shawn}<-(#10322)]"
2:
  "textcolour"=12632256
  "backcolour"=0
  "length"=249
  "style"=0
  "text"=" As you enter, Barrabus lifts a hand in greeting. "Welcome t' th' Fighters Guild! If yer new here, I c'n answer some questions! (OOC: Information is available via '+fg/info'. '+fg/help' will give you help on commands that work on the Guild grounds)."


Notice the space at the start of style #2?

One approach would be to omit a leading space at the start of the second style, if you know it is style #2, like this:


    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        if k == 2 then
          text = string.gsub (text, "^ ", "")
        end -- leading space on first style run
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 


If it isn't always style #2 you might have to have a flag which checks if you have output anything yet, and if not trim the first space, eg.


function pnp.nospoof.gather(name, line, wildcards, styles)
    --print(wildcards[1])
    local noSpoof = string.gsub(wildcards[1], "[%^%$%(%)%%%.%{%}%[%]%*%+%-%?]", "%%%1")
    noSpoof = string.gsub(noSpoof, "^%s", "")
    local outputted = false
    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        if not outputted then
          text = string.gsub (text, "^ ", "")
        end -- leading space on first output
        if #text > 0 then
          outputted = true
        end  -- if
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 
    
    Note()
end

- Nick Gammon

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

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #23 on Wed 21 Sep 2016 02:37 AM (UTC)
Message
Quote:

Back to the MU*, the following lines are still not being edited out by the gsub


What are you expecting to happen? When I tested it the spoof stuff was gone:


(New BB message (4/46) posted to 'IC Requests' by Jessamyn: Looking for a knight)

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #24 on Wed 21 Sep 2016 09:57 AM (UTC)
Message
Nick Gammon said:

Quote:

1) What's with the unnecessary indent?


The indent is because you don't get rid of the space after the spoof stuff. If you tprint the style runs you see this:


1:
  "textcolour"=8454143
  "backcolour"=0
  "length"=34
  "style"=0
  "text"="[Barrabus(#9443){Shawn}<-(#10322)]"
2:
  "textcolour"=12632256
  "backcolour"=0
  "length"=249
  "style"=0
  "text"=" As you enter, Barrabus lifts a hand in greeting. "Welcome t' th' Fighters Guild! If yer new here, I c'n answer some questions! (OOC: Information is available via '+fg/info'. '+fg/help' will give you help on commands that work on the Guild grounds)."


Notice the space at the start of style #2?


Yes. I should have realized that was what was happening, damn.

Also, I was trying several ways yesterday to print the styles table so I could get a better idea of what was going on. Tried searching the site for a "tables" display. Didn't find tprint, it feels so obvious in retrospect, to see if there was a t-something.

Nick Gammon said:

One approach would be to omit a leading space at the start of the second style, if you know it is style #2, like this:


    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        if k == 2 then
          text = string.gsub (text, "^ ", "")
        end -- leading space on first style run
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 


If it isn't always style #2 you might have to have a flag which checks if you have output anything yet, and if not trim the first space, eg.


function pnp.nospoof.gather(name, line, wildcards, styles)
    --print(wildcards[1])
    local noSpoof = string.gsub(wildcards[1], "[%^%$%(%)%%%.%{%}%[%]%*%+%-%?]", "%%%1")
    noSpoof = string.gsub(noSpoof, "^%s", "")
    local outputted = false
    for k,v in ipairs(styles) do
        text = string.gsub(v.text, noSpoof, "")
        if not outputted then
          text = string.gsub (text, "^ ", "")
        end -- leading space on first output
        if #text > 0 then
          outputted = true
        end  -- if
        ColourTell(RGBColourToName(v.textcolour), RGBColourToName(v.backcolour), text)
    end 
    
    Note()
end



This code

    noSpoof = string.gsub(noSpoof, "^%s", "")


Was intended to get rid of the space. I assume it didn't work since the line was not yet split. Which simply indicates that I need to understand how style runs work better first.

Question...

If the first gsub isn't clearing out the nospoof stuff, what IS it doing?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #25 on Thu 22 Sep 2016 03:54 AM (UTC)
Message
The noSpoof stuff didn't have a space in it (certainly not a leading space).

A style run is neither more nor less than a bunch of text, with associated colour information (plus underline etc.).

So something like:

Text: foo
Colour: red
Background: green
Bold: yes

And a line is simply one or more of those style runs.

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #26 on Thu 22 Sep 2016 04:18 AM (UTC)
Message
So, what exactly is the purpose of the first gsub then?
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #27 on Thu 22 Sep 2016 09:21 PM (UTC)
Message
In reply #8? That is to convert the noSpoof stuff so that it is a regular expression with all the "magic" characters escaped out.

- Nick Gammon

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

Posted by Tesagk   (52 posts)  [Biography] bio
Date Reply #28 on Sat 24 Sep 2016 01:52 PM (UTC)

Amended on Sat 24 Sep 2016 10:15 PM (UTC) by Nick Gammon

Message
Nick Gammon said:

In reply #8? That is to convert the noSpoof stuff so that it is a regular expression with all the "magic" characters escaped out.


OK. Sorry for the "newbie" questions, but what's the point of turning it back into a regular expression?

Also,

[bbpocket(#21){Core}<-(#20)] (New BB message (4/46) posted to 'IC Requests' by Jessamyn: Looking for a knight)
[SGP - Main Globals(#6){Core}<-(#9256)] Ceel goes OOC.


For some reason, these don't end up matching. Not entirely certain why, as the new trigger pattern is quite open, and the gsub accounts for all of the special characters that might be found in the line.
[Go to top] top

Posted by Nick Gammon   Australia  (22,975 posts)  [Biography] bio   Forum Administrator
Date Reply #29 on Sat 24 Sep 2016 10:12 PM (UTC)
Message
Quote:

what's the point of turning it back into a regular expression?


OK, take this spoof stuff you want to get rid of:


[bbpocket(#21){Core}<-(#20)] 


As it stands when used in string.gsub on its own, it is just a "set". That is, it matches a single character, where that character can be any one of:


  • b
  • b
  • p
  • o
  • c
  • k
  • e
  • t
  • (
  • #
  • 2
  • 1
  • )
  • {
  • C
  • o
  • r
  • e
  • }
  • < to (
  • #
  • 2
  • 0
  • )


That's how sets work. It just looks for any one of the thing in the square brackets.

Now obviously we don't want that, so we have to "escape" out things like square brackets so they don't have their special meaning. That's what the first string.gsub does.

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


81,019 views.

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

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]