Jump to content
DorianaCele

Best way to listen for about 10 specific messages?

You are about to reply to a thread that has been inactive for 289 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello,

One of my object uses a listening channel (say /222) to receive configuration commands (such as start, stop, etc). There are about 10 commands, all start with prefix "config:". So command 1 may be "/222 config:start" and command 2 may be "/222 config:stop". What I am wondering is, for this situation, is it better to write 10 llListen() on channel 222, each for one specific command; or to just do one llListen() on Channel 222 for anything, then analyze what the message is in the listen() event? And, is there a way to just write one llListen() which triggers the listen() event only when the received message has a specific prefix (in this case it is "config:")? "Better" means more efficient and consumes less CPU time. Thank you very much. 

Share this post


Link to post
Share on other sites

There's no way to listen for, like, a regular expression, so a single llListen() would need to get everything on the channel and then analyze it. The thing is, even if you had ten separate llListen()s, the messages would still end up in one listen() event queue to analyze anyway, so the only advantage of the multiple llListen()s would be to specify tight filters on which messages can possibly wake up your script. As long as it's not using a high traffic channel (such as 0), that's not likely to be a problem, so I'd favor a single, wide-open llListen().

You can maybe experiment to find the fastest way for the listen() handler to exclude any messages received that don't match the overall pattern, and be efficient about the order in which you test for the individual commands.

(Aside: I suspect that even in pre-Mono days, ten separate llListen()s would be too many to be a net benefit (except maybe on channel 0), but tight listen filters were a bigger deal back then because script execution was so many times slower than testing filters in native code.)

  • Like 2

Share this post


Link to post
Share on other sites

You can only have one listen event, usually when several channels are anticipated the value of the channel parameter is checked for specific values.

Since you have a specific channel your simplest option is then to look for the substring in the message using llGetSubString, and then use a set of ifs to look at what is following that substring and process them accordingly.

An alternative is to have a list containing all the commands that follow "config:", and use llListFindList to find a match for the command, the resulting integer will be -1 (not found), or 0,1,2... and you can then process the command accordingly.

If the sender of the messages will always be the same person or object, the LLlisten event when set up can be told to listen for messages from a specific name or specific uuid.

 

(Qie beat me to it :)

Edited by Profaitchikenz Haiku
  • Like 2

Share this post


Link to post
Share on other sites
45 minutes ago, Qie Niangao said:

so I'd favor a single, wide-open llListen().

 

43 minutes ago, Profaitchikenz Haiku said:

your simplest option is then to look for the substring in the message using llGetSubString, and then use a set of ifs

So I think both of you favor a single llListen() on anything rather than 10 separate llListen() on specific messages. Thank you!

  • Like 2

Share this post


Link to post
Share on other sites
1 hour ago, Profaitchikenz Haiku said:

An alternative is to have a list containing all the commands that follow "config:", and use llListFindList to find a match for the command, the resulting integer will be -1 (not found), or 0,1,2... and you can then process the command accordingly.

this ^^ what Prof said

a thing with parse to list is that when ":" is used as the delimiter then list cmd = ["config","start"] or ["config", "stop"] etc

so can check:  if (llList2String(cmd, 0) == "config) { arg = llList2String(cmd, 1) }

where this approach gets super useful is when some cmds have 1 argument and others have more than one.  Example: "config:color:blue".  "config:orient:up" "config:orient:down" etc

if (llList2String(cmd, 1) == "color" { tint = llList2String(cmd, 2) }

 

  • Like 3

Share this post


Link to post
Share on other sites
4 hours ago, DorianaCele said:

So I think both of you favor a single llListen() on anything rather than 10 separate llListen() on specific messages. Thank you!

It's pretty awkward but no matter what you do, you'll end up writing at least 10 if-checks for those 10 messages.

Share this post


Link to post
Share on other sites
You are about to reply to a thread that has been inactive for 289 days.

Please take a moment to consider if this thread is worth bumping.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...