An "intercom" system.
|
|
Kain Davis
Registered User
Join date: 12 Jul 2005
Posts: 5
|
07-26-2005 16:46
Howdy! I would like to script an intercom system. But I am not sure how to go about it. I have experiance in C++, PHP, Basic, ect. However I have not yet mastered the second life functions and how all that flows together. So heres the "problem": I have 2 objects. A speaker object and the actual intercom peice you speak into. What I want to do is make it so you can place the speaker some where away from the intercom and talk into the intercom with a command such as "ic Test message here" and the speaker would broadcast that message. Any tips about how to do this? Im not sure how to have interaction between two seperate objects. Thanks in advance!
|
|
fr0b Assia
Registered User
Join date: 6 Jun 2005
Posts: 10
|
07-26-2005 20:17
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
07-26-2005 20:25
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|
|
Kain Davis
Registered User
Join date: 12 Jul 2005
Posts: 5
|
07-26-2005 20:31
No I understand that aspect. I dont understand how to make it work between two seperate ob jects. I could easily make a one object version but that would just defeat that purpose. 
|
|
Minsk Oud
Registered User
Join date: 12 Jul 2005
Posts: 85
|
07-26-2005 22:33
The llWhisper/Say/Shout functions will cause a listen event on llListening remote objects (within range), the llEmail/llGetNextEmail will do similar by key or over longer distances. So for an example (stolen mostly from the wiki, and not compiled because my SL has an average uptime of about 45 seconds): The speaker (named "Speaker" so the microphone can ignore it): default { state_entry() { // Listen for the microphone to "say" something llListen(53, "Microphone", "", NULL_KEY); }
listen( integer channel, string name, key id, string message ) { // When it does relay the message llSay(0, message); } }
The microphone (named "Microphone", so the listen above will work): default { state_entry() { // Listen for anyone nearby to say something llListen(0, "", "", NULL_KEY); }
listen(integer channel, string name, key id, string message) { // Make sure we do not re-relay things the speaker has said if (name != "Speaker") { // When someone does, relay it to the speaker llShout(53, message); } } }
Make more sense?
|
|
Kain Davis
Registered User
Join date: 12 Jul 2005
Posts: 5
|
07-26-2005 23:05
I sure does! Thanks alot!
|
|
Malachi Petunia
Gentle Miscreant
Join date: 21 Sep 2003
Posts: 3,414
|
07-26-2005 23:27
As you are just starting with LSL, I thought I'd mention that "open" listens (i.e. llListen(0, "", NULL_KEY, ""  ) are considered a generally Bad Thing as they require that your script run for anything said in chat within hearing range. Depending on the application you may wish to llListen(0, "", llGetOwner(), ""  ; where the script need only process things said by the owner of the "transmitter" or you could make it listen on some non-zero channel (e.g. 54) and then to use it you can chat /54 message to transmit which does put a burden on the user to remember "/54" but subsequent lines can be abbreviated // my second message Depending on what you are trying to accomplish you may need an open listen, but they do tend to slow the simulator if used indiscriminately. To draw a crude analogy: in C++, you can do read(fd, buf, 1) but it is way more efficient for the system if you "istream >> c".
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
07-27-2005 02:07
Depending on positions, distances and uses you could also use link messages between the objects if they're linkable.
That does impose some limits on you, but you speak into the microphone prim and it transmits the message to the speaker prim one way only and off you go.
|
|
Jesrad Seraph
Nonsense
Join date: 11 Dec 2004
Posts: 1,463
|
07-27-2005 02:10
key current_user; integer handle;
default { state_entry() { current_user = NULL_KEY; } touch_start(integer i) { if (current_user != NULL_key) { if (llDetectedKey(0) == current_user) { llSetTimerEvent(0.1); } else llWhisper(0, "Already in use."); } else { current_user = llDetectedKey(0); llSetText("In use by: " + llDetectedName(0), <1,1,1>, 1.0); handle = llListen(0, "", current_user, ""); llSetTimerEvent(30.0); } }
listen(integer chan, string name, key id, string message) { llShout(53, message); llSetTimerEvent(30.0); }
timer() { llListenRemove(handle); llSetText("", ZERO_VECTOR, 0.0); current_user = NULL_KEY; llSetTimerEvent(0.0); } }
Here is another microphone script where one person at a time speaks into the intercom, activating it by touching the microphone then speaking normally (only this person's words being relayed), then touching it again or waiting 30 seconds to deactivate. This way when the intercom is not used it wont cause lag.
_____________________
Either Man can enjoy universal freedom, or Man cannot. If it is possible then everyone can act freely if they don't stop anyone else from doing same. If it is not possible, then conflict will arise anyway so punch those that try to stop you. In conclusion the only strategy that wins in all cases is that of doing what you want against all adversity, as long as you respect that right in others.
|
|
Kain Davis
Registered User
Join date: 12 Jul 2005
Posts: 5
|
Listen help
07-30-2005 01:40
So I have been playing with this code. And for whatever reason I can NEVER get listen to work(in any of my scripts mind you). I dont understand. I have exactly what is givin in other scripts, but it never works for me... Here is what I have for the speaker: default { state_entry() { llSay(0, "Online"); // Listen for the microphone to "say" something llListen(53, "mic", "", NULL_KEY); }
listen( integer channel, string name, key id, string message ) { // When it does relay the message llSay(0, message); } }
And here is what I have for the microphone. default { state_entry() { llSay(0,"Online"); // Listen for anyone nearby to say something llListen(0, "", llGetOwner(), NULL_KEY); }
listen(integer channel, string name, key id, string message) { // Make sure we do not re-relay things the speaker has said if (name != "speaker") { // When someone does, relay it to the speaker llShout(53, message); } } }
I dont understand it. Once again I have never been able to get listen to work with any of my custom scripts... Thanks in advance.
|
|
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
|
07-30-2005 03:34
You're not declaring the listens properly: From: Kain Davis llListen(53, "mic", "", NULL_KEY);
llListen(0, "", llGetOwner(), NULL_KEY);
should be: llListen(53, "mic", NULL_KEY, ""); llListen(0, "", llGetOwner(), "");
respectively. Note you can use "" in place of NULL_KEY, so you could have: llListen(53, "mic", "", ""  ; If you look at the listen event - which you've declared properly it goes: listen(interger channel, string name, key ID, string message)
llListen(); defines them in the same order, channel to listen on, name to listen to, key to listen to, message to listen for. Putting blanks in anything after channel makes it open on that field, so llListen(0, "", "", ""  ; is pretty much the nightmare scenario - it listens to everything anyone says on channel 0. The reason you're not getting an errror is that NULL_KEY, and all keys, are special cases of strings and implicitly typecast strings, so you're listeners are listening for someone saying the NULL_KEY string, which is a load of 0 and - in some order I can't remember right now.
|
|
Kain Davis
Registered User
Join date: 12 Jul 2005
Posts: 5
|
07-30-2005 14:38
Thanks alot!
|