Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Assistance in combining two llMessageLinked scripts into one.

Psyra Extraordinaire
Corra Nacunda Chieftain
Join date: 24 Jul 2004
Posts: 1,533
10-03-2006 11:37
I use a script in the eyes of my avatars to let them blink randomly, as well as have a control to make them stay closed or open. Now, I'd also like to add a similar control/slave script that uses llMessageLinked as well to let the eyes be turned in different directions (by adjusting the texture offsets).

Trick is, I don't know how to combine two seperate random timer functions that call llMessageLinked without them listening to each other. :)

Here's the script for the blinking eyes. They use two textures and swap them at random 1-10 second intervals with a 0.5 second long blink. If you enter the channeled command, they stay closed until opened manually.

The Eye Controller Script:
CODE

default
{
state_entry()
{
llSetTimerEvent(llFrand(10));
}

timer()
{
llMessageLinked( LINK_ALL_OTHERS, 1, "", NULL_KEY ) ;
}
}


The Eye Slave Script:
CODE

integer closed=0;

default
{
state_entry()
{
key owner = llGetOwner();
llListen(16,"",owner,"");
}

on_rez(integer start_params)
{
llResetScript();
}

link_message( integer sender, integer num, string message, key id )
{
if( num == 0 )
{
llSetTexture("eyeclose", ALL_SIDES);
llSleep(0.2);
llSetTexture("eyeopen", ALL_SIDES);
llSetTimerEvent(llFrand(10));
}

else if (closed == 0)
{
llSetTexture("eyeclose", ALL_SIDES);
llSleep(0.2);
llSetTexture("eyeopen", ALL_SIDES);
llSetTimerEvent(llFrand(10));

}
}

listen( integer channel, string name, key id, string message )
{
if( message == "eyeclose" )
{
closed = 1;
llSetTexture("eyeclose", ALL_SIDES);
}
if( message == "eyeopen" )
{
closed = 0;
llSetTexture("eyeopen", ALL_SIDES);
}

}

}


Generally, I'd like to add a second controller and slave for the eye movement, but the scripts would conflict! Any thoughts how to add a second timer in the same object that would have its OWN slave scripts and that each slave would specifically listen to each controller without listening to each other's? :)

Edit: yea, I know something is funky with the Slave script. But it doesn't affect the working of the blink script, so I never bothered to debug that part. ;D
_____________________
E-Mail Psyra at psyralbakor_at_yahoo_dot_com, Visit my Webpage at www.psyra.ca :)

Visit me in-world at the Avaria sims, in Grendel's Children! ^^
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
10-03-2006 11:47
Not sure if i understand what's happening in your script there, but it seems to me if you get rid of the llSetTimerEvent() calls in the slave script (which doesn't have timer() event for that matter) you can make both eyes blink simultaneously in response to 'blink' link message generated by the Eye Controller script just fine? Except the blink controller sends "1" as tick signal, while the eyes would blink after receiving "0" in link message... o.O
Psyra Extraordinaire
Corra Nacunda Chieftain
Join date: 24 Jul 2004
Posts: 1,533
10-03-2006 12:10
When set with slave scripts, the eyes do properly blink at the same time.

The root prim of the head contains the controller. Each eye contains the slave scripts. When the timer goes off it calls the blink function in both eyes at the same time. :)

Trick is, I want to add a SECOND timer to the same root prim, to trigger different link_message's in the same eye prims... so besides randomly blinking, they will also randomly look back and forth using llSetPrimativeParameters(PRIM_TEXTURE, etc) to adjust texture offsets. :)

As it is now, I can simply add more function into the listen in the slaves to MANUALLY move the eyes (such as 'if( message == "eyeright" )' or 'if( message == "eyeleft" )' or the like) but I'd like to make the movement random if possible. :)

So, to sum up:

- Want to have two independant timers that perform two seperate functions, or have one timer that alternates between one and the other.
- Controller scripts share the same root prim, slave scripts share the same child prims.

The general question is... How would I change the llMessageLinked to send two different messages, and link_message{} segments of each script so that they can discern which message is which.

Controller Script Mock-Up:

-Random function 1-10 seconds.
-On time event, either calls llMessageLinked("Do the blink thing";) or llMessageLinked("Do the eye movement thing";) - alternating. Or, have two random timers that each call one function.

Slave Script Mock-Up:

- Listens for "Do the blink thing" or "Do the eye movement thing" and does whichever is appropriate.
_____________________
E-Mail Psyra at psyralbakor_at_yahoo_dot_com, Visit my Webpage at www.psyra.ca :)

Visit me in-world at the Avaria sims, in Grendel's Children! ^^
Joannah Cramer
Registered User
Join date: 12 Apr 2006
Posts: 1,539
10-03-2006 12:25
From: Psyra Extraordinaire
Trick is, I want to add a SECOND timer to the same root prim, to trigger different link_message's in the same eye prims... so besides randomly blinking, they will also randomly look back and forth using llSetPrimativeParameters(PRIM_TEXTURE, etc) to adjust texture offsets. :)

Ahh, i see ^^

something like this could work, then:
CODE

// controller

tick() { llSetTimerEvent( llFrand(9.0) + 1.0 ); }

default {

state_entry() { tick(); }

timer() {

// generate random 0 or 1 to choose exact action
if( llFloor(llFrand( 2.0 )) == 0 ) {
llMessageLinked( LINK_ALL_OTHERS, 0, "eye_blink", NULL_KEY );
}
else {
llMessageLinked( LINK_ALL_OTHERS, 0, "eye_move", NULL_KEY );
}

tick();
}
}

// receiver
default {

state_entry() { llListen( 16, "", llGetOwner(), "" ); }

on_rez(integer start_params) { llResetScript(); }

listen( integer channel, string name, key id, string message ) {

if( message == "eyeclose" ) { closed = 1; llSetTexture("eyeclose", ALL_SIDES); }
else if( message == "eyeopen" ) { closed = 0; llSetTexture("eyeopen", ALL_SIDES); }
}

link_message( integer sender, integer num, string message, key id ) {

if( closed == 1 ) return; // eyes closed so no use checking details anyway

if( message == "eye_blink" ) {
// do teh blink thing
}
else if( message == "eye_move" ) {
// do teh move thing
}
}
}
Psyra Extraordinaire
Corra Nacunda Chieftain
Join date: 24 Jul 2004
Posts: 1,533
10-03-2006 13:15
I'll give this a shot when I get home from work, Joannah .... if it works I owe you a gift! ^^

PS: THanks for debugging the extra flak outta it too, it looks like, ^^

Edit: it did INDEED work! I'll definately be forwarding something special your way! ^^
_____________________
E-Mail Psyra at psyralbakor_at_yahoo_dot_com, Visit my Webpage at www.psyra.ca :)

Visit me in-world at the Avaria sims, in Grendel's Children! ^^