Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

script problem milliseconds

cecino Cicerone
Registered User
Join date: 3 Feb 2007
Posts: 4
08-10-2007 07:37
hi too all
im writing on this script and got some troubles to add milliseconds,
is there any idear how i can integrate them? its a script for time measure.
when iam finish with that i will post it on the
scripting library,
but without milliseconds its not god.
thanks a lot for any tip

integer g_Seconds = 0;
integer g_Minutes = 0;
integer g_Hours = 0;
integer g_Ticking = FALSE;
integer info = llGetAgentInfo;
vector g_TextColor = <1,1,1>;


string zero_pad(integer number)
{
if(number < 10) return "0" + (string)number;
return (string)number;
}


default
{
state_entry()
{

llSetText("00:00:00", g_TextColor, TRUE);
llSensorRepeat( "", NULL_KEY, AGENT, 5, PI,1);

llListen(5000, "", "", "";);

llSetTimerEvent(g_Ticking);
}

sensor(integer num_detected)
{

g_Ticking = !g_Ticking;
llSetTimerEvent(g_Ticking);

}


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

message = llToLower(message);
if(message == "reset";)
{

g_Ticking = FALSE;
llSetTimerEvent(0);
llSetText("00:00:00", g_TextColor, TRUE);
llSay(0,(string)zero_pad(g_Minutes)+":"+(string)zero_pad(g_Seconds));
g_Seconds = 0; g_Minutes = 0; g_Hours;
}
}

timer()
{

g_Seconds++;


if(g_Seconds >= 60)
{

g_Minutes++;
g_Seconds = 0;


if(g_Minutes >= 60)
{

g_Hours++;
g_Minutes = 0;
}
}


llSetText(zero_pad(g_Hours) + ":" + zero_pad(g_Minutes) + ":" +zero_pad(g_Seconds), g_TextColor, TRUE);
}
}
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
08-10-2007 08:22
I don't think your timer events will be accurate to the degree that you want as timer events can skew depending on the current script load of the sim, you may simply want to us llGetTimeStamp for the current time, and subtract the time that the test started at.

http://rpgstats.com/wiki/index.php?title=LlGetTimestamp
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
08-10-2007 08:24
Only problem with timestamp is that it won't run in milliseconds...

...Shadow is right that your timer won't be totally millisecond accurate.

I've found that trying to do millisecond-accurate scripting in SL is quite a chore and there is not much help for it in the functions (as only timer and llsleep to my knowledge run at a millisecond level)
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
08-10-2007 09:40
In the scripting library, there are a couple of Timer scripts that try to be very accurate. i think about 10ms is the best you can do, and often less precise.

Go look at the various timer scripts in the Library.

lee
cecino Cicerone
Registered User
Join date: 3 Feb 2007
Posts: 4
tenth seconds
08-13-2007 04:46
hi
first thanks for the replys.
so i test a little and i think its running stable with tenth seconds. i will test it some more and post it in the scripting library.
thanks