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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Lua misbehaving in a trigger

Lua misbehaving in a trigger

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


Posted by Ada   (20 posts)  [Biography] bio
Date Fri 19 Aug 2011 09:28 AM (UTC)
Message
Hi! I was trying to make a trigger to separate clothes from description in Lusternia but I'm having a weird issue with Lua in it. I'm using MUSHclient version 4.77. The following is the trigger I made:


<triggers>
  <trigger
   enabled="y"
   keep_evaluating="y"
   match="^(He|She) is (.+) (He|She) is wearing (.+)$"
   omit_from_output="y"
   regexp="y"
   send_to="12"
   sequence="100"
  >
  <send>local data = "%0"
local gender = "%1"

local clothindex = string.find(data, "is wearing")
local description = string.sub(data, 1, clothindex - 2)
local reversed = string.reverse(description)
local lastperiod = string.find(reversed, "%.")
local description = string.sub(description, 1, string.len(description) - lastperiod + 1)

local clothes = string.sub(data, clothindex, string.len(data))
local lastperiod = string.find(clothes, "%.")
local clothes = string.sub(clothes, 1, lastperiod)
local clothes = gender .. " " .. clothes

local clothindex = string.find(data, clothes)
if clothindex then
  description = description .. string.sub(data, clothindex + string.len(clothes), string.len(data))
end

local clothes = string.gsub(clothes, "is wearing", "is wearing:\n")
local clothes = string.gsub(clothes, ",", ",\n")

ColourNote("lightgrey", "", description)
ColourNote("lightgrey", "", clothes)</send>
  </trigger>
</triggers>


And here's a sample match text:
Quote:

She is a bouncing furrikin and stands at just under four feet in height. Her body is lithely built, with sensuous curves in all the right places. She is covered in thick, jet-black fur, with streaks of silver on her face and two wide bands running down the length of her tail, ending in a large patch at the tip. Her ears are triangular and stand straight up, twitching in response to any sound, while her tail sways gently from side to side. Her eyes burn with the brilliant orange of sunset, and contain flecks of azure and violet. They seem unable to focus on any one thing for long, and her gaze constantly shifts around the area. Her face is unmarked by the passage of time, save for the many thick scars curling down the right side of her face. The longest starts just below her eye and curls under her chin, and is crossed intermittently by shorter scars at irregular angles. She is wearing a golden lion brooch, a braided ring of opal and moonstone, a shining silver scabbard, a slender sapphire collar of brushed suede, a delicate snowflake earring through her left ear, a silver bracelet of snowflakes, a delicate snowflake earring through her right ear, velvet robes of snow and ice, a golden bear brooch, a thin opal bracelet carved with lilies, 3 pocketbelts and a twilight blue rose. Tattooed on her arms is the illustration of a twining vine with large leaves.


But I keep getting this error:
[string "Trigger: "]:15: unfinished string near '"is wearing:'

However, if I take the trigger script and paste it in the Immediate box, give the variables data = <matchtext above> and gender = <She> (the text the trigger would assign) and click Run it works!

I'm not sure if I'm using the keyword 'local' too much or too little. I'd appreciate any help regarding this. Thanks!

Love,
Ada
[Go to top] top

Posted by Ada   (20 posts)  [Biography] bio
Date Reply #1 on Fri 19 Aug 2011 09:29 AM (UTC)
Message
Err.. the error message is:
Compile error
World: Lusternia
Immediate execution
[string "Trigger: "]:20: unfinished string near '"is wearing:'

.. I re-pasted the trigger above and didn't get the new error line.
[Go to top] top

Posted by Ada   (20 posts)  [Biography] bio
Date Reply #2 on Fri 19 Aug 2011 09:47 AM (UTC)
Message
Oh umm.. this is the output I'm trying to achieve:
She is a bouncing furrikin and stands at just under four feet in height. Her body is lithely built, with sensuous curves in all the right places. She is covered in thick, jet-black fur, with streaks of silver on her face and two wide bands running down the length of her tail, ending in a large patch at the tip. Her ears are triangular and stand straight up, twitching in response to any sound, while her tail sways gently from side to side. Her eyes burn with the brilliant orange of sunset, and contain flecks of azure and violet. They seem unable to focus on any one thing for long, and her gaze constantly shifts around the area. Her face is unmarked by the passage of time, save for the many thick scars curling down the right side of her face. The longest starts just below her eye and curls under her chin, and is crossed intermittently by shorter scars at irregular angles. Tattooed on her arms is the illustration of a twining vine with large leaves.
She is wearing:
 a golden lion brooch,
 a braided ring of opal and moonstone,
 a shining silver scabbard,
 a slender sapphire collar of brushed suede,
 a delicate snowflake earring through her left ear,
 a silver bracelet of snowflakes,
 a delicate snowflake earring through her right ear,
 velvet robes of snow and ice,
 a golden bear brooch,
 a thin opal bracelet carved with lilies,
 3 pocketbelts and a twilight blue rose.


I wish they'd make a CONFIG CLOTHESLINE like Achaea :s Oh well.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Fri 19 Aug 2011 10:10 AM (UTC)
Message
Quote:

local clothes = string.gsub(clothes, "is wearing", "is wearing:\n")


The treatment of data in the "send" box expands out \n to be a newline, before it hits Lua. So Lua is seeing:



local clothes = string.gsub(clothes, "is wearing", "is wearing:
")


Hence the error message. If you want to do that, in a send box, make the \n to be \\n.

By the way, why go to all that trouble to find the person's description. Isn't it just wildcard %4?

- Nick Gammon

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

Posted by Ada   (20 posts)  [Biography] bio
Date Reply #4 on Fri 19 Aug 2011 12:48 PM (UTC)
Message
Ahh, yay! Thanks, it is working now. I'm just too used to how things are presented Achaea heh. You can do CONFIG CLOTHESLINE ON there to see clothing in other adventurers' on separate lines from the rest of their description.

There's no such option in Lusternia and what people look like and what they're wearing is all mashed up in a single huge paragraph. This trigger fixes that. Thanks again!
[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.


12,704 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]