Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Help with Link message and for loop

Gomez Bracken
Who said that??
Join date: 12 Apr 2007
Posts: 479
06-28-2007 06:04
Hi

I have a script which calls a second script on an event.

The second script is a countdown timer.

If the event on the first (master) script happens again and the link message is resent, I need the countdown timer on the second script to restart. This is not happening, as it's waiting for the for loop to finish first.

Any ideas?

Here is the timer in the second script:

integer i;
string str;

default
{

link_message(integer sender_num, integer num, string str, key id)

{
for (i=180; i > 0; i--)
{
llSetText("timer started "+ (string)i +" seconds left", <0, 1.0, 0>, 1);
llSleep(1.0);

}
}
}

The script will send a single string variable (once working properly) to the second script.

Here is the call from the first script:

llMessageLinked(LINK_SET, 0, (string)total, NULL_KEY);

All I need to happen is when the event in the main script is triggerd (it's using an IF condition), this script resets and starts the countdown again with the new variable content, instead of waiting for the for loop to finish first.

I'm sure it must be simple, but after several hours of banging my head against the wall, I need ideas (and more coffee!).

Any help would be much appreciated.

Gomez
Domino Marama
Domino Designs
Join date: 22 Sep 2006
Posts: 1,126
06-28-2007 06:30
Doing the countdown in a loop with a sleep will block other events. Use a timer so other events have a chance to be processed.

CODE

integer i;
string data;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
data = str;
i = 180;
llSetTimerEvent( 1.0 );
}
timer()
{
if ( --i <=0 )
{
llSetText("timer stopped", <0, 1.0, 0>, 1);
llSetTimerEvent (0.0 );
}
else
{
llSetText("timer started "+ (string)i +" seconds left", <0, 1.0, 0>, 1);
}
}
}
Gomez Bracken
Who said that??
Join date: 12 Apr 2007
Posts: 479
06-28-2007 09:45
Fantastic - just thr trick!

Thanks for your help.

GOmez
From: Domino Marama
Doing the countdown in a loop with a sleep will block other events. Use a timer so other events have a chance to be processed.

CODE

integer i;
string data;

default
{
link_message(integer sender_num, integer num, string str, key id)
{
data = str;
i = 180;
llSetTimerEvent( 1.0 );
}
timer()
{
if ( --i <=0 )
{
llSetText("timer stopped", <0, 1.0, 0>, 1);
llSetTimerEvent (0.0 );
}
else
{
llSetText("timer started "+ (string)i +" seconds left", <0, 1.0, 0>, 1);
}
}
}