Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with a simple script

Myra Graves
Registered User
Join date: 7 Mar 2007
Posts: 2
03-27-2007 14:22
Hi,

i tried to write a script, which listens to the public chat and if a keyword is written, to stop a movement.
But it lookslike the listener doesn't work.

Can u help me please!!!!

Here is the script:

integer iSteps = 2;
vector vOffset = <0.0, 0.0, 0.2>;
vector vBase;
float fOpenTime = 0.0;
integer continue = TRUE;
string Keyword = "stopit";

default
{
state_entry()
{
vBase = llGetPos();
llListen(0,"",NULL_KEY,Keyword);
}

listen(integer chan, string name, key id, string msg)
{
continue = FALSE;
llSay(0,"stopped";);
}

touch_start(integer count)
{
do{
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
}while(continue);
}

}




THX for your help

Myra
Baron Hauptmann
Just Designs / Scripter
Join date: 29 Oct 2005
Posts: 358
03-27-2007 14:55
CODE

integer iSteps = 2;
vector vOffset = <0.0, 0.0, 0.2>;
vector vBase;
float fOpenTime = 0.0;
integer continue = TRUE;
string Keyword = "stopit";

default
{
state_entry()
{
vBase = llGetPos();
llListen(0,"",NULL_KEY,Keyword);
}

listen(integer chan, string name, key id, string msg)
{
continue = FALSE;
llSay(0,"stopped");
}

touch_start(integer count)
{
do{
integer i;
vector basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
basepos = llGetPos();
for (i = 0; i < iSteps; i++)
{
llSetPos(basepos + i*vOffset);
}
vOffset *= -1;
}while(continue);
}

}


(php tags just help make it easier to read)

The problem is that since LSL is event-driven, you are stuck in the dowhile loop waiting for the variable continue to change. But while LSL is busy trying to resolve this loop, it does not get around to handling the next event, namely listening. So it never breaks out of the cycle.

You might be better off, say putting this in a timer event which continues to fire. Each iteration could be a timer event, and then inbetween, it would check for the chat trigger.

Baron H.
Myra Graves
Registered User
Join date: 7 Mar 2007
Posts: 2
03-27-2007 15:04
thx a lot for your help
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
03-28-2007 01:10
If you havent already try using a timer rather than the while loop.

CODE

integer iSteps = 2;
vector vOffset = <0.0, 0.0, 0.2>;

string Keyword = "stopit";

integer Counter;

default
{
state_entry()
{
llListen(0,"",NULL_KEY,Keyword);
llSetTimerEvent(0);
Counter = 0;
}

listen(integer chan, string name, key id, string msg)
{
llSay(0,"stopped");
llSetTimerEvent(0);
}

touch_start(integer count)
{
llSetTimerEvent(0.2);
}

timer()
{
vector basepos = llGetPos();
llSetPos(basepos + vOffset);

++Counter;
if(Counter >= iSteps)
{
vOffset *= -1;
Counter = 0;
}
}
}