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

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Name Trigger

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Name Trigger
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please).
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Pages: 1 2  

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sun 06 Feb 2011 12:03 AM (UTC)  quote  ]

Amended on Sun 06 Feb 2011 12:05 AM (UTC) by Nick Gammon

Message
You can't directly put tables into variables. However it is easy enough with serialization:

http://www.gammon.com.au/forum/?id=4960

For example with this test data:



-- example table - in practice you would make an alias to add them

names = {
 ["a funny looking clown"] = "Tom",
 ["a sleepy fellow"] = "John",
 ["a pretty girl"] = "Sarah",

-- more here

}


Put this into the "on world save" callback:


require "serialize"

SetVariable ("saved_names", "names = " .. serialize.save_simple (names))


Now if you look at the (MUSHclient) variable "saved_names" (in the variables configuration dialog) you see this:


names = {
  ["a sleepy fellow"] = "John",
  ["a pretty girl"] = "Sarah",
  ["a funny looking clown"] = "Tom",
  }


This will now be saved as part of the world file, whenever you save that.

Next time (using the "world open" script callback) you put the names back like this:


assert (loadstring (GetVariable ("saved_names") or "")) ()


That converts the "string" table into an actual table.

So much for saving and loading.

Now to use in the trigger. Do the following whenever the list of names changes:


function getNames ()
 local t = {}
 for k, v in pairs (names) do
   table.insert (t, k)
 end
 SetVariable ("names_match", table.concat (t, "|"))
end


I use a second table here to convert the descriptions/names into a numerically-keyed table of just the descriptions. Then table.concat puts a "|" between each one.

Thus now names_match is:


a sleepy fellow|a pretty girl|a funny looking clown


Finally we can use the variable names_match in the trigger by putting it there with "expand variables" checked. Also note the use of the "!" which stops MUSHclient trying to put a backslash in front of the "|" characters ...


<triggers>
  <trigger
   enabled="y"
   expand_variables="y"
   ignore_case="y"
   match="^(.*?)(@!names_match)(.*?)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="110"
  >
  <send>

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "%2" then
    ColourTell ("white", "", " (" ..
      (names ["%2"] or "unknown") ..
       ")")
   end -- if
end

Note ""  -- start new line

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

- Nick Gammon

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

Posted by Skasi   (3 posts)  [Biography] bio
Date Sat 05 Feb 2011 11:42 PM (UTC)  quote  ]

Amended on Sat 05 Feb 2011 11:47 PM (UTC) by Skasi

Message
That's more or less exactly what I needed, thanks! :)

Is it possible to use variables as arrays? Is there a way to use scripts in 'match'? I would like to do something like the following:

function getNames()
 local names = GetVariable("names")
 for i in ipairs(names) do
  print(i)
  if i < #names then print("|") end
 end
end

match="^(.*?)(getNames())(.*?)$"
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 03 Feb 2011 12:28 AM (UTC)  quote  ]
Message
This is one way of doing the colours:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="*funny looking clown*"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "a funny looking clown" then
    ColourTell ("white", "", " (Tom)")
   end -- if
end

Note ""  -- start new line

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


The appending of the name here depends on the description "a funny looking clown" being in its own style run (that is, all the same colour).

Skasi said:

Also is there a way to access the string between the asterisks?


You can do that if you make it a regular expression. Hit the "convert to regular expression" button, and then add brackets around the middle bit. This also lets you do a more general solution. eg.


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="^(.*?)(a funny looking clown|a sleepy fellow|a pretty girl)(.*?)$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="110"
  >
  <send>

friends = {
 ["a funny looking clown"] = "Tom",
 ["a sleepy fellow"] = "John",
 ["a pretty girl"] = "Sarah",

-- more here

}

-- show each style in its original colour

for i, style in ipairs (TriggerStyleRuns) do
  ColourTell (RGBColourToName (style.textcolour), RGBColourToName (style.backcolour), style.text)

  -- if person's description, append their name
  if style.text == "%2" then
    ColourTell ("white", "", " (" ..
      (friends ["%2"] or "unknown") ..
       ")")
   end -- if
end

Note ""  -- start new line

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


This keeps a table of friends, and then uses a regular expression to check for one of them.

You could improve this a bit by generating the matching names into a variable rather than having to repeat all the descriptions.
Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.




- Nick Gammon

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

Posted by Skasi   (3 posts)  [Biography] bio
Date Wed 02 Feb 2011 03:10 PM (UTC)  quote  ]

Amended on Wed 02 Feb 2011 03:24 PM (UTC) by Skasi

Message
Is there a way to retain wildcard coloring?
<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="*funny looking clown*"
   send_to="14"
   sequence="110"
  >
  <send>
    Tell ("", "", "%1")
    ColourTell ("magenta", "", "funny looking clown")
    ColourTell ("white", "", "(Tom)")
    Tell ("", "", "%2")
  </send>
  </trigger>
</triggers>

eg. <white>All of a sudden, </white><magenta>a funny looking clown</magenta><white>(Tom) hurls </white><green>a red-nose</green><white> at you!</white>


Also is there a way to access the string between the asterisks?
For something like this.
ColourTell ("magenta", "", "<string between *s>")
ColourTell ("white", "", "(Tom)")
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Tue 17 Aug 2010 09:12 PM (UTC)  quote  ]

Amended on Tue 17 Aug 2010 09:13 PM (UTC) by Nick Gammon

Message
Jdiddleymspot said:

Hmm..I don't know the codes for this forum. But I would like the man's description in purple and the rest of the text in the normal format for the mud. Is that possible?


There are no colour codes on the forum. :)

Anything is possible. You can use any colour you want in displays (there is an inbuilt colour-picker to help choose one). You could display %0 in one colour and "Barry" in another, like this:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="A blue eyed man with short hair *"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>

ColourTell ("purple", "", "%0 ")
ColourNote ("white", "", "(Barry)")

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


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


The ColourTell leaves the text on the same line.

If you are still having problems please paste what you have:

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

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

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Tue 17 Aug 2010 06:55 PM (UTC)  quote  ]

Amended on Wed 18 Aug 2010 07:15 AM (UTC) by Jdiddleymspot

Message
Hmm..I tried to find out myself, but I failed :(

What do I need to insert so that it would look like this...

[color=purple]A blue eyed man with short hair[/color] looks about shadily.

Hmm..I don't know the codes for this forum. But I would like the man's description in purple and the rest of the text in the normal format for the mud. Is that possible?

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Tue 17 Aug 2010 05:12 AM (UTC)  quote  ]
Message
Thanks Nick, I'll try that later today! :)

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Mon 16 Aug 2010 09:35 PM (UTC)  quote  ]
Message
Jdiddleymspot said:

I've tried using the FAQ, but it's not so easy. This is what I've figure out so far with the FAQ and just by messing around....

---------------------------------
Trigger: A blue eyed man with short hair *

Tick Ignore case & Omit from output

Send box:
A blue eyed man with short hair %1 (Barry)

Send to: Output
-------------------

It seems to work, but the output is always blue.


It helps to use the Copy button:

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.



However you are on the right track. It is in blue because sending to output defaults to the world "note" colour.

To control the colour, you can script a short ColourNote instead, like this:


<triggers>
  <trigger
   enabled="y"
   ignore_case="y"
   match="A blue eyed man with short hair *"
   omit_from_output="y"
   send_to="14"
   sequence="110"
  >
  <send>ColourNote ("purple", "", "%0 (Barry)")</send>
  </trigger>
</triggers>


Template:pasting For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.


I used %0 which will echo the entire original line, and then added (Barry) to the end.

- Nick Gammon

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

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Mon 16 Aug 2010 05:00 PM (UTC)  quote  ]

Amended on Mon 16 Aug 2010 06:44 PM (UTC) by Jdiddleymspot

Message
Firstly, I'm sorry if I came across pushy. I really didn't mean to sound that way. I just thought that maybe my post would get lost amongst the others. I apologize.

Here is what I posted after I asked if a trigger can just trigger on a PC description:-

Jdiddleymspot said:

If you need more information about what the MUD sends, then this is it:-

MUD said:

A Room is Here
Exits: North, East, South, West

Room description goes here. Roughly a paragraph in length.

A table is here.
An arrow is here (x3).
A blue eyed man with short hair is here.



I'm sorry, but I don't know what scripting language I use. I AM really a total newbie at this sort of thing. If it helps, I'm trying to use the GAME>CONFIGURE>TRIGGERS box.

You are indeed correct that upon seeing this:-

A blue eyed man with short hair is here.

I want to see this:-

A blue eyed man with short hair is here (Barry).

The brackets part (Barry) I will input myself. There is no way for MUSHCLIENT to know his name is Barry, but I would like his name to show after I tell the program his name is barry.

I've tried using the FAQ, but it's not so easy. This is what I've figure out so far with the FAQ and just by messing around....

---------------------------------
Trigger: A blue eyed man with short hair *

Tick Ignore case & Omit from output

Send box:
A blue eyed man with short hair %1 (Barry)

Send to: Output
-------------------

It seems to work, but the output is always blue. The normal color for mobiles on the MUD is always purple.

I'm playing Shadows of Isildur (www.middle-earth.us) A Diku mud as far as I'm aware, though I don't actually know what that means :(

This is about as far as I've got. Once again, sorry for coming across pushy. I really didn't mean to.

John

Ps. I'm using MushClient v.4.43



Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 14 Aug 2010 09:14 PM (UTC)  quote  ]

Amended on Sat 14 Aug 2010 10:14 PM (UTC) by Nick Gammon

Message
Jdiddleymspot said:


Posted at Saturday, 02:52 AM Australian time

Basically, what I want is for when a PC or NPC description is displayed on screen, it will put his/her/its name in brackets after the description. How do I do this?


...

Jdiddleymspot said:

Please help :)


...

Jdiddleymspot said:


Posted at Saturday, 10:01 PM Australian time

Can't it trigger on the description of the PC?


...

Jdiddleymspot said:


Posted at Sunday, 06:11 AM Australian time

Can't it trigger on the description of the PC?


Making multiple posts won't get your questions answered faster. You asked a question at 10 PM my time, and then tried to hurry us up at 6 AM my time. Personally I was asleep.

When you made your initial post you were asked to supply, amongst other things, the scripting language you use, and the version of MUSHclient. You haven't done so.

I asked this:

Nick Gammon said:

How do we know, from what you posted, to put the name Barry there?


You haven't answered that.

Are you saying that every time you see this line:


A blue eyed man with short hair is here.


You want to replace it with:


A blue eyed man with short hair is here. (Barry)


Is that just because you happen to know that this person is Barry?

Is that description part of a longer description (like some MUDs do, with many people listed in one paragraph)?

It would help to know which MUD you are talking about.

If you are talking about a longer paragraph then an actual example would help too.

Are you planning to replace many descriptions with names, or just a single one (Barry)?

Sure, it can be done by triggering on the description, assuming you happen to know which name matches which description (which you didn't say).

But if you have hundreds of them there might be a better way. And if the descriptions are inside a big paragraph then the paragraph would have to be broken down into individual descriptions.

Have you read the FAQ?

The people who visit these forums are generally very helpful, and will be happy to help you tidy up an attempt that you have made. But they need information to work on, and generally like you to show you have tried to solve the problem yourself.

- Nick Gammon

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

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Sat 14 Aug 2010 07:11 PM (UTC)  quote  ]
Message
Can't it trigger on the description of the PC?

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Sat 14 Aug 2010 12:24 PM (UTC)  quote  ]

Amended on Sat 14 Aug 2010 12:31 PM (UTC) by Jdiddleymspot

Message
If you need more information about what the MUD sends, then this is it:-

MUD said:

A Room is Here
Exits: North, East, South, West

Room description goes here. Roughly a paragraph in length.

A table is here.
An arrow is here (x3).
A blue eyed man with short hair is here.

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Sat 14 Aug 2010 11:01 AM (UTC)  quote  ]
Message
Can't it trigger on the description of the PC?

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Sat 14 Aug 2010 09:20 AM (UTC)  quote  ]
Message
Jdiddleymspot said:

Hi, basically the mud sends ^me something like...

A blue eyed, tall man is here.

I want it to say....

A blue eyed, tall man is here (Barry)


How do we know, from what you posted, to put the name Barry there?

- Nick Gammon

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

Posted by Jdiddleymspot   (11 posts)  [Biography] bio
Date Sat 14 Aug 2010 08:12 AM (UTC)  quote  ]
Message
Please help :)

Jdidds
www.middle-earth.us
Roleplaying in Middle-Earth
[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.


3,972 views.

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

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

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

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]