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 ➜ Lua ➜ Parsing quotes in an emote

Parsing quotes in an emote

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


Posted by Terry   USA  (87 posts)  Bio
Date Tue 24 Jun 2008 12:55 AM (UTC)
Message
I apologize in advance for this post. I'm almost religious about not asking other people to write scripts for them. However, I have no idea how to even begin with parsing in a script.
Anyway, I was trying to figure out a way of parsing quotes ("" and `' if possible :D) in an emote so that the script will colorcode the emote correctly based on if there is speech or not. Unfortunately, after trying for about half an hour and getting nowhere, I decided I'd come to you guys :P Really I only need help figuring out how to parse something, and I can probably figure out the rest :)

The hard part comes in because I don't know beforehand how many quotes there will be. If I knew there would only be one set of quotes per emote, then I'd be able to do it. But I really don't know how many. It's roleplay, not a movie. :)
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #1 on Tue 24 Jun 2008 01:27 AM (UTC)
Message
I'm not sure what you mean by "parsing quotes", perhaps you could give an example.

However you can put quotes in strings by escaping them, like this:


print ('I see Nick\'s cat here')



- Nick Gammon

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

Posted by Terry   USA  (87 posts)  Bio
Date Reply #2 on Tue 24 Jun 2008 01:43 AM (UTC)
Message
Something like:
> emote smirks at the man. "Yeah right, John." Adding with a shrug, "I guess that would add to our sales income though." He smirks again, still laughing softly at your comment.

I'm trying to make a script that would colorize all the text between quotes ("Yeah right..." and "I guess...")
Top

Posted by Nick Gammon   Australia  (23,158 posts)  Bio   Forum Administrator
Date Reply #3 on Tue 24 Jun 2008 03:09 AM (UTC)

Amended on Tue 24 Jun 2008 03:13 AM (UTC) by Nick Gammon

Message
This is the best I could do. I had hoped to use one large regexp, but couldn't think of a way of doing it. ;)


<triggers>
  <trigger
   enabled="y"
   match="Nick *"
   omit_from_output="y"
   send_to="14"
   sequence="100"
  >
  <send>

do
  local line = "%0"  -- copy matching line into variable
  local i = 1  -- start at column 1
  
  -- customize this!
  local normal_colour = "white"
  local quote_colour = "blue"
  
  -- keep processing the line, looking for quoted sections
  while i &lt; #line do
    
    -- find opening quote
    local quote, _, closing_quote = line:find ([=[(['"])]=], i + 1)
    if not quote then
      break
    end -- no quote found
    
    -- show up to the quote
    ColourTell (normal_colour, "", line:sub (i, quote))
    
    -- find closing quote
    local end_quote = line:find (closing_quote, quote + 1) or #line
    
    -- show quoted stuff in different colour
    ColourTell (quote_colour, "", line:sub (quote + 1, end_quote - 1))

    -- next loop iteration is past the quote    
    i = end_quote
    
  end -- while
  
  -- finish off line
  ColourNote (normal_colour, "", line:sub (i))
end

</send>
  </trigger>
</triggers>



Basically the script loops looking for quoted sections. You will need to adjust the trigger match to whatever works for you, and plug in some more appropriate colours.


- Nick Gammon

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

Posted by WillFa   USA  (525 posts)  Bio
Date Reply #4 on Sat 26 Jul 2008 10:23 AM (UTC)
Message
Wouldn't this be Simpler?


foo="Someone says: \"Purple PeanutButter is yummy!\" and you have to laugh as you think \"Idiot.\"."

for q in foo:gmatch("(%b\"\")") do 
   print (q) 
end
Top

Posted by Terry   USA  (87 posts)  Bio
Date Reply #5 on Mon 28 Jul 2008 09:46 PM (UTC)
Message
Hmm, when I tried that, all I got was
Quote:
"Purple PeanutButter is yummy!"
"Idiot."
Also, I'm not quite sure how that would even work... You mean I'd have to use some regexp thing to fire through that trigger? I don't quite get what you're doing.
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.


16,993 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.