Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Discussion -Working Age Detector-

Shippou Oud
The Fox Within
Join date: 11 Jul 2005
Posts: 141
01-07-2007 15:42
Here is my version of an age detector, usefull for determining age of an av when clicked.
CODE

string us;
default
{
on_rez(integer x)
{
llResetScript();
}
state_entry()
{
llSetText("Touch me to get your age",<.8,0,.8>,1);
}

touch_start(integer x)
{
llRequestAgentData(llDetectedKey(0), DATA_BORN);
us = llKey2Name(llDetectedKey(0));

}
dataserver(key queryid, string data)
{

list birthday = llParseString2List( data, ["-"], [] ) ;
integer byear = (integer)llList2String( birthday, 0 ) ;
integer bmonth = (integer)llList2String( birthday, 1 ) ;
integer bday = (integer)llList2String( birthday, 2 ) ;
// Line Break
string ts = llGetDate();
list now = llParseString2List( ts, ["-"], [] ) ;
integer nyear = (integer)llList2String( now, 0 ) ;
integer nmonth = (integer)llList2String( now, 1 ) ;
integer nday = (integer)llList2String( now, 2 ) ;
integer fy = (nyear * 365) - (byear * 365);
float fm = (nmonth * 30.5) - (bmonth * 30.5);
integer fd = nday - bday;
float sage = fy + fm + fd;
integer age = (integer) sage;

llSay(0,"" + us + " is " + (string) age + " days old!");

}
}

There was some debate earlier on using some long and confusing math to convert this to that to something else to get an age, but I found K_I_S_S (keep it simple, stupid) to be the best aproch to the problem.
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Original Thread
01-15-2007 23:11
/15/07/159175/1.html
_____________________
i've got nothing. ;)