Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Timing problem

Owner Maltese
Registered User
Join date: 13 Sep 2005
Posts: 65
09-23-2005 09:48
Thanks everyone.
With the help of the Ping Pong thread I got a way of making something move up and down by voice command and touch. I have one problem. I want it speed up or slow down. The script is presently set for five speeds but it only travels in one.

Here is the script. Any suggestions?

CODE

vector whereamI;
vector Imgoingwhere;
vector Imnowat;
integer attarget;
integer listen_handle;
float thingspeed;


movethething()
{
if (attarget == 0)
{
llSetPos(Imgoingwhere);
attarget = 1;
}
else
{
llSetPos(whereamI);
attarget = 0;
}

}



default
{
state_entry()
{
attarget = 0;
thingspeed = 0;
whereamI = llGetPos();
Imgoingwhere = whereamI + <0,0,0.3>;
llSetStatus(STATUS_PHANTOM,TRUE);
llSetAlpha(0,ALL_SIDES);
llListenRemove(listen_handle);
listen_handle = llListen(3006,"",NULL_KEY,"");
}

timer()
{
movethething();
}

listen(integer channel, string name, key id, string message)
{
if (message == "move 1")
{
llSetAlpha(1,ALL_SIDES);
llSetStatus(STATUS_PHANTOM,FALSE);
thingspeed = 4;
llSetTimerEvent(thingspeed);
}
else if (message == "move 2")
{
thingspeed = 2;
}
else if (message == "move 3")
{
thingspeed = 1;
}
else if (message == "move 4")
{
thingspeed = 0.5;
}
else if (message == "move 5")
{
thingspeed = 0.001;
}
else if (message == "stop")
{
thingspeed = 0;
llSetPos(whereamI);
llSetTimerEvent(0);
llSetStatus(STATUS_PHANTOM,TRUE);
llSetAlpha(0,ALL_SIDES);
}
else if (message == "show")
{
llSetAlpha(1,ALL_SIDES);
}
}


touch_start(integer total_number)
{
if (thingspeed == 0)
{
llSetAlpha(1,ALL_SIDES);
llSetStatus(STATUS_PHANTOM,FALSE);
thingspeed = 4;
}
else if (thingspeed == 0.001)
{
thingspeed = 0;
llSetStatus(STATUS_PHANTOM,TRUE);
llSetAlpha(0,ALL_SIDES);
}
else if (thingspeed == 0.5)
{
thingspeed = 0.01;
}
else
{
thingspeed = thingspeed / 2;
}
}
}


As always, thanks for your help.

Owner
Online Doesburg
absurd hero
Join date: 6 Jul 2005
Posts: 53
09-23-2005 10:28
Move the llSetTimerEvent(thingspeed) out of the first if-block and place it after(!) the last if - block that asigns a value to the 'thingspeed' variable. That would be the "stop", in your case.

You can deal with the last if-block seperately.

CODE

//...
if (message == "move 1")
{
llSetAlpha(1,ALL_SIDES);
llSetStatus(STATUS_PHANTOM,FALSE);
thingspeed = 4;
//llSetTimerEvent(thingspeed); <== not needed here
}
//...rest of "move X" messages ...
else if (message == "stop")
{
thingspeed = 0;
llSetPos(whereamI);
llSetStatus(STATUS_PHANTOM,TRUE);
llSetAlpha(0,ALL_SIDES);
}

llSetTimerEvent(thingspeed); <== put it here,

if (message = "show")
{
llSetAlpha(1,ALL_SIDES);
}
//...


The only problem with that it is that it will reset the timer each time there is a message on the channel you specified (even if it's a wrong message), but since thingspeed doesn't change it shouldn't cause a problem (just a quick pause, probably).

Basically, you need to reset the timer each time the thingspeed variable changes to see an effect.

BTW, llSetPos and a bunch of other calls have a built in sript delay, so your fast speeds probably wont work anyways.
_____________________
"The evil that is in the world almost always comes of ignorance, and good intentions may do as much harm as malevolence if they lack understanding." - Albert Camus