LSL tutorial: Communication between parent and child
Back when I started to write complex scripts, one of the first puzzles I needed to solve was this: Object A rezzes object B out of its inventory, and needs to send some startup information to B. How can it do this?
When A rezzes B, the only information it can pass to it in the call to llRezObject is a single integer. When object B wakes up, its on_rez event receives that integer as the start_param. But suppose you need to send more information than that? Then A has to send it by encoding it into a string and speaking it. The channel it is going to speak on can be sent as the start parameter.
This won’t work:
In A:
llRezObject( channelNumber, ... );
llSay( channelNumber, ... );
In B:
on_rez( integer channelNumber ) {
llListen( channelNumber, ... );
}
The reason is that A cannot assume that B is listening, or even exists, by the time that A speaks. Spoken messages are never queued: if no-one is listening, they are not heard. How can A make sure that when it speaks to B, B is already rezzed and listening?