Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

How to vary timer event speed?

Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
11-19-2008 01:25
Hi all I have the following script in an object I wan to be able to vary the roation speed from 0 seconds to 1 second.
It works other than the speed varying bit, I can't work out what order I should put state entry etc to make it adjustable.




float rotate=0;
float RotSpeed;
default
{
link_message(integer sender_num, integer num, string msg, key id)
{
//if(msg!="";) llOwnerSay("Recieved "+msg);
if(msg=="Ft0";) RotSpeed=.0;
if(msg=="Ft1";) RotSpeed=.1;
if(msg=="Ft2";) RotSpeed=.2;
if(msg=="Ft3";) RotSpeed=.3;
if(msg=="Ft4";) RotSpeed=.4;
if(msg=="Ft5";) RotSpeed=.5;
if(msg=="Ft6";) RotSpeed=.6;
if(msg=="Ft7";) RotSpeed=.7;
if(msg=="Ft8";) RotSpeed=.8;
if(msg=="Ft9";) RotSpeed=.9;
if(msg=="Ft10";) RotSpeed=1.0;
}

state_entry()
{
rotate = 0;
llSetTimerEvent(RotSpeed);
//llOwnerSay((string)RotSpeed);
}

timer()
{
rotate = rotate + .1;
if (rotate==10.1)
{
rotate = 0;
}
llRotateTexture(rotate,ALL_SIDES);
}
}
_____________________
Level 38 Builder [Roo Clan]

Free Waterside & Roadside Vehicle Rez Platform, Desire (88, 17, 107)

Avatars & Roadside Seaview shops and vendorspace for rent, $2.00/prim/week, Desire (175,48,107)
Very Keynes
LSL is a Virus
Join date: 6 May 2006
Posts: 484
11-19-2008 04:59
state_entry is only called when the state changes, try this instead

float rotate=0;
float RotSpeed;
default
{
link_message(integer sender_num, integer num, string msg, key id)
{
//if(msg!="";) llOwnerSay("Recieved "+msg);
if(msg=="Ft0";) RotSpeed=.0;
if(msg=="Ft1";) RotSpeed=.1;
if(msg=="Ft2";) RotSpeed=.2;
if(msg=="Ft3";) RotSpeed=.3;
if(msg=="Ft4";) RotSpeed=.4;
if(msg=="Ft5";) RotSpeed=.5;
if(msg=="Ft6";) RotSpeed=.6;
if(msg=="Ft7";) RotSpeed=.7;
if(msg=="Ft8";) RotSpeed=.8;
if(msg=="Ft9";) RotSpeed=.9;
if(msg=="Ft10";) RotSpeed=1.0;
rotate = 0;
llSetTimerEvent(RotSpeed);
//llOwnerSay((string)RotSpeed);
}

timer()
{
rotate = rotate + .1;
if (rotate==10.1)
{
rotate = 0;
}
llRotateTexture(rotate,ALL_SIDES);
}
}
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-19-2008 11:14
also note that sim time dilation affects timers

if you want to try to beat that, setting the timer by multiplying the time by the time dilation can help (up to a point)... just be sure to include a failsafe for under .5 time dilation or it could get ugly
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
11-19-2008 13:19
Cool, thanks, that solved the problem. Probably not woried about dilation that much as it's only an animation script so not critical to be perfect by any means, but that will come in handy for another one later :)
_____________________
Level 38 Builder [Roo Clan]

Free Waterside & Roadside Vehicle Rez Platform, Desire (88, 17, 107)

Avatars & Roadside Seaview shops and vendorspace for rent, $2.00/prim/week, Desire (175,48,107)
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
11-19-2008 14:14
And try doing half the work. Just have the sender script send the float instead of Ft0 for instance.


CODE

float rotate = 0;
float RotSpeed;
default {
link_message(integer sender_num, integer num, string msg, key id) {
RotSpeed = (float)msg;
rotate = 0;
llSetTimerEvent(RotSpeed);
//llOwnerSay((string)RotSpeed);
}

timer() {
rotate += .1;
if (rotate == 10.1) {
rotate = 0;
}
llRotateTexture(rotate, ALL_SIDES);
}
}
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
SuezanneC Baskerville
Forums Rock!
Join date: 22 Dec 2003
Posts: 14,229
11-19-2008 14:26
Isn't "rotate == 10.1" one of those "testing for equality of floats" one sees repeated warnings about?
_____________________
-

So long to these forums, the vBulletin forums that used to be at forums.secondlife.com. I will miss them.

I can be found on the web by searching for "SuezanneC Baskerville", or go to

http://www.google.com/profiles/suezanne

-

http://lindenlab.tribe.net/ created on 11/19/03.

Members: Ben, Catherine, Colin, Cory, Dan, Doug, Jim, Philip, Phoenix, Richard,
Robin, and Ryan

-
Tegg Bode
FrootLoop Roo Overlord
Join date: 12 Jan 2007
Posts: 5,707
11-19-2008 15:00
From: Jesse Barnett
And try doing half the work. Just have the sender script send the float instead of Ft0 for instance.


CODE

float rotate = 0;
float RotSpeed;
default {
link_message(integer sender_num, integer num, string msg, key id) {
RotSpeed = (float)msg;
rotate = 0;
llSetTimerEvent(RotSpeed);
//llOwnerSay((string)RotSpeed);
}

timer() {
rotate += .1;
if (rotate == 10.1) {
rotate = 0;
}
llRotateTexture(rotate, ALL_SIDES);
}
}

Yep I would have done it this way except I'm still working out what values are noticble in differences for the speed range :)
_____________________
Level 38 Builder [Roo Clan]

Free Waterside & Roadside Vehicle Rez Platform, Desire (88, 17, 107)

Avatars & Roadside Seaview shops and vendorspace for rent, $2.00/prim/week, Desire (175,48,107)
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-19-2008 19:22
From: SuezanneC Baskerville
Isn't "rotate == 10.1" one of those "testing for equality of floats" one sees repeated warnings about?

yup....better to use a 1-10 scale for the message and then /10 for the final usage
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Osgeld Barmy
Registered User
Join date: 22 Mar 2005
Posts: 3,336
11-19-2008 19:44
or half arse it and typecast it as a string