Simple script involving dates
|
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
|
02-08-2010 19:00
I'm trying to do the following.
1) When an object rezzes it finds out todays date. 2) Calculates the date two days from now 3) Stores that date in the prim only if this date is null
From then on, when the prim with the script rezzes it uses llgetdate to get todays date, compares it to the current date.
If the current date is greater than or equal to the stored date, the object gives a message and all scripts are inactive.
I'm new, but making good progress at scripting.
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-08-2010 19:24
From: yevka Laws I'm trying to do the following.
1) When an object rezzes it finds out todays date. 2) Calculates the date two days from now 3) Stores that date in the prim only if this date is null
From then on, when the prim with the script rezzes it uses llgetdate to get todays date, compares it to the current date.
If the current date is greater than or equal to the stored date, the object gives a message and all scripts are inactive.
I'm new, but making good progress at scripting. There is nothing simple about dates. Is March 1st 2 days later then February 27? It is unless it is a leap year for example. The only reliable way to use actual dates is to create a calendar library. Alternatively for your application, all you really need to do is use llGetTime and llResetTime. Two days from the last time the time was reset would be 48 hrs x 60 minutes x 60 seconds = 172,800 seconds. Compare this against (integer)llGetTime().
_____________________
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
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-08-2010 19:32
Borrowing a function from http://wiki.secondlife.com/wiki/LlGetDate, you can write something like this.......... integer dayOfYear(integer year, integer month, integer day) { return day + (month - 1) * 30 + (((month > 8) + month) / 2) - ((1 + (((!(year % 4)) ^ (!(year % 100)) ^ (!(year % 400))) | (year <= 1582))) && (month > 2)); } default { on_rez (integer start_param) { list dateComponents = llParseString2List(llGetDate(), ["-"], []); integer year = (integer) llList2String(dateComponents, 0); integer month = (integer) llList2String(dateComponents, 1); integer day = (integer) llList2String(dateComponents, 2); integer DayNumber = dayOfYear(year, month, day); if (llGetObjectDesc() == " ") { integer TwoDaysAway = DayNumber + 2; llSetObjectDesc((string) TwoDaysAway); } else if (DayNumber > (integer)llGetObjectDesc()) { llSay(0,"This object is more than two days old."); llSetScriptState(llGetScriptName(),FALSE); } } }
It ought to work.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-08-2010 19:35
BTW, Luv & hugs Rolig!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
_____________________
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
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-08-2010 19:40
Awwww... You too, Jesse. See you on the other side... 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
|
My script so far
02-08-2010 20:56
integer dayOfYear(integer year, integer month, integer day) { return day + (month - 1) * 30 + (((month >  + month) / 2) - ((1 + (((!(year % 4)) ^ (!(year % 100)) ^ (!(year % 400))) | (year <= 1582))) && (month > 2)); } default { // Set Object Expire Date and Delete self state_entry() { list dateComponents = llParseString2List(llGetDate(), ["-"], []); integer year = (integer) llList2String(dateComponents, 0); integer month = (integer) llList2String(dateComponents, 1); integer day = (integer) llList2String(dateComponents, 2); integer DayNumber = dayOfYear(year, month, day); integer TwoDaysAway = DayNumber + 2; llSetObjectDesc((string) TwoDaysAway); llRemoveInventory(llGetScriptName()); } } The Object Description is not being set and the script is not deleting itself.
|
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
|
02-08-2010 21:02
Make sure the script is set to running.
_____________________
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
|
yevka Laws
Commander Eva "Yevka" Law
Join date: 19 Jul 2006
Posts: 32
|
02-08-2010 21:04
From: Jesse Barnett Make sure the script is set to running. You were right. Very helpful. String is stored as 42 Today is 40. I'm ready to implement. Is there a way to change the function to pick the number of days since 1970 or something so the thing doesn't mess up at year end? Such good, fast tips
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-08-2010 21:22
Oh. Well, you do need to store the day of the year somewhere, because that's really the only way you'll be able to do your comparison correctly. If you ALSO need to store the date, though, all you need to do is pack them together, like this ... llSetObjectDesc((string) TwoDaysAway + "| Today is " + llGetDate()); That stores both bits of information in the object description. To get them back out, you write integer SavedNo = llGetSubString(llGetObjectDesc(),0,llSubstringIndex(llGetObjectDesc(),"|"  -1); and string SavedDate = llGetSubString(llGetObjectDesc(),llSubstringIndex(llGetObjectDesc(),"|"  +10,-1); Then you can do whatever you want with the two pieces of information. ETA: Ooop! You changed the request after I started typing this response. If you're really worried about the end of the year, remember that's always December 31. So all you need to do is write a little test to see if your first rez date is Dec 30 or 31, and then adjust for that specific case.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
02-09-2010 03:09
I may be missing something here, but can't you just store the unix time in the description and do. if(llGetUnixTime() > ((integer)llGetObjectDesc() + 172800)) { //do stuff }
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-09-2010 06:22
Yes, but not if you wanted to do literally what the OP asked for. He didn't want to test for whether the object was more than 24 hours old. He wanted to know whether the day on which it was re-rezzed was more than two days after the day when it was first rezzed. So, for example, if it was first rezzed at 11;59 p.m. on Feb 7 he wanted to declare it dead it if was rezzed for the second time at 12:01 a.m. on February 9 --- just 24 hrs and 2 minutes later. That's why I used a calendar, not a clock.
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
02-09-2010 06:38
From: Rolig Loon Yes, but not if you wanted to do literally what the OP asked for. He didn't want to test for whether the object was more than 24 hours old. He wanted to know whether the day on which it was re-rezzed was more than two days after the day when it was first rezzed. So, for example, if it was first rezzed at 11;59 p.m. on Feb 7 he wanted to declare it dead it if was rezzed for the second time at 12:01 a.m. on February 9 --- just 24 hrs and 2 minutes later. That's why I used a calendar, not a clock. Yes, thats why I said I may be missing something. I sort of assumed it would be for use in a demo object, you get to play with it for 48 hours then it dies. If it really is a matter of the day rather than the elapsed time I agree you do need to go with a calender. Edit: Thinking a bit more about this Store the future date in the description with llSetObjectDesc((string)((integer)((llGetUnixTime() + 172800)/86400))); and do the comparion with if((integer)(llGetUnixTime()/86400) >= (integer)llGetObjectDesc()) { // do stuff }
Should I think do what the OP wanted and compare the elapsed days.
|
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
|
02-09-2010 08:44
this stops working 24 hours of actual in world running time (allowing for dilation that causes slow running) AFTER a new owner (who is not the creator) first rezzes it. it cannot be reset to working by anyone but the creator integer gIntEnd = 86400;;
default{ state_entry{ if (llGetOwner() == llGetCreator()) state sReady; } }
state sReady{ changed( integer vBitChg ){ if (CHANGED_OWNER & vBitChg){ state sWorking; } } }
state sWorking{ state_entry(){ llResetTime(); llSetTimerEvent( 60.0 ); }
//-- other working code goes here
timer(){ if (llGetTime() > gIntEnd){ llResetScript(); } } }
ETA: fixed small logic error ETA2: I have timestamp conversion functions linked in the library and on my user page in the LSL_Portal for date handling too and from unix timestamps... they are compatible with llGetDate, llGetTimestamp, and llGetUnixTime
_____________________
| | . "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... | - 
|
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
|
02-09-2010 09:02
From: Void Singer this stops working 24 hours of actual in world running time (allowing for dilation that causes slow running) AFTER a new owner (who is not the creator) first rezzes it. it cannot be reset to working by anyone but the creator integer gIntEnd = 86400;;
default{ state_entry{ if (llGetOwner() == llGetCreator()) state sReady; } }
state sReady{ changed( integer vBitChg ){ if (CHANGED_OWNER & vBitChg){ state sWorking; } } }
state sWorking{ state_entry(){ llResetTime(); llSetTimerEvent( 60.0 ); }
//-- other working code goes here
timer(){ if (llGetTime() > gIntEnd){ llResetScript(); } } }
ETA: fixed small logic error ETA2: I have timestamp conversion functions linked in the library and on my user page in the LSL_Portal for date handling too and from unix timestamps... they are compatible with llGetDate, llGetTimestamp, and llGetUnixTime But if you restart the sim once a day it will run for ever.  PS: llGetTime() is unaffected by time dilation.
|
Rolig Loon
Not as dumb as I look
Join date: 22 Mar 2007
Posts: 2,482
|
02-09-2010 09:40
Nice! From: Void Singer ETA2: I have timestamp conversion functions linked in the library and on my user page in the LSL_Portal for date handling too and from unix timestamps... they are compatible with llGetDate, llGetTimestamp, and llGetUnixTime I stumbled on your unix timestamp conversions a couple of days ago but they were in a different corner of my brain last night. As Beverly suggested too, I can now see how that route would work. As usual, I took the brute force path instead. 
_____________________
It's hard to tell gender from names around here but if you care, Rolig = she. And I exist only in SL, so don't ask....  Look for my work in XStreetSL at 
|