Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with a status indicator.

Bobby Dayton
Test Pilot for Airfix
Join date: 15 Nov 2003
Posts: 206
05-05-2006 00:44
I have a script running which is in effect an online status indicator. I have added an extra prim which will be a small visual indicator like an LED which will show red or green. What is the best way for the main script to communicate with the script in this indicator prim. I am not sure if I should use llMessageLinked or llSay on a private channel.

If anyone has an example of how to do this then it would be very much appreciated.
Adriana Caligari
Registered User
Join date: 21 Apr 2005
Posts: 458
05-05-2006 01:17
If the indicator is only going to be used to show red or green then it is best not to have a script in it at all.

Just isolate what it's link number is ( a little look up in the start of the main script that finds the name and stores the link number ) then use llSetLinkColor to change the appropriate prim.

eg

CODE

string indicator_name = "my indicator" ;
integer idx;
integer link_number;
for ( idx = 2 ; idx <= llGetNumberOfPrims( ) ; idx ++ )
{
if ( llGetLinkName( idx ) == indicator_name )
{
link_number = idx;
}
}


That finds the link number - you said you have the on-line detection code so this bit assumes you have set online to be either TRUE or FALSE.

CODE

//
if ( online )
{
llSeLinkColor( link_number, <0,1,0>, ALL_SIDES );
}
else
{
llSetLinkColor( link_number, <1,0,0>,ALL_SIDES );
}
//


That changes the prim color.
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
05-05-2006 01:30
link them up and use link messages if possible. For something like this your gain is making it not spoofable, and fractionally less lag (a listen on an odd channel that doesn't get hit that often won't slow things down that much).

It depends a bit on how you've set it up, but in outline something like:
CODE

if(online) llMessageLinked(LINK_ALL_OTHERS, 0, "<0.0, 1.0, 0.0>, "");
else llMessageLinked(LINK_ALL_OTHERS, 0, "<1.0, 0.0, 0.0>, "");

in the detector prim and:
CODE

link_message(integer sender, integer prim, string msg, key id)
{
llSetColor((vector)msg, ALL_SIDES);
}

Should work just fine.

Of course, depending on complexity etc. this might be even nicer:
CODE

if(online) llSetLinkColor(LINK_ALL_OTHERS,<0.0, 1.0, 0.0>,ALL_SIDES);
else llSetLinkColor(LINK_ALL_OTHERS, <1.0, 0.0, 0.0>, ALL_SIDES);

Is even simpler to set up and use...

There are caveats about the if statements - updating the prims' colour every few seconds is wasteful and laggy - setting it up so you check to see if the status has changed and only sending the colour change then is nicer to the sim, even if it's nastier to the code.
Frans Charming
You only need one Frans
Join date: 28 Jan 2005
Posts: 1,847
05-05-2006 02:03
Also consider what time interval you want to use to detect if someone is online or not. It is tempting to check every second, but once in every five minutes will do the job just as well.
_____________________
Bobby Dayton
Test Pilot for Airfix
Join date: 15 Nov 2003
Posts: 206
05-05-2006 02:26
Thanks to all the replies.

Frans, the scan rate is set at 1 minute at the moment. I might extend it.


I think I uderstand how you found the link number in the first example. If the object consisted of only 2 prims then would I be safe using an id of 2.

I am not sure how the LINK_ALL_OTHERS works Eloise. It suggests that it affects all prims in an object. If that is the case would it change colour of the main prim as well as the indicator.
Frans Charming
You only need one Frans
Join date: 28 Jan 2005
Posts: 1,847
05-05-2006 03:46
It will change all prims except the prim that the script is in.
_____________________
Eloise Pasteur
Curious Individual
Join date: 14 Jul 2004
Posts: 1,952
05-05-2006 04:35
LINK_ALL affects the whole link set.

LINK_ALL_OTHERS affects, as you might guess, everything except the prim the script is in.

LINK_ROOT affects just the root (although using 1 works just as well)

LINK_ALL_CHILDREN affects everything except the root prim.

(Sorry if they're slighly syntactically wrong - can't have this and the wiki open on the fun machines they give me at work.)