Jump to content
You are about to reply to a thread that has been inactive for 79 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Posted

So, i have a simple HUD game, that allows the players to collect points.
But i want the HUD to reset the points to zero, at midnight on Sunday ( SL time )
and i also need to take care of people who were offline sunday, and don't come back until later in the week.
 
I was initially thinking of tracking the week number, but unfortunately, i found nothing in the date libraries for generating that from a unix time

But i'm really not sure what the best way to approach this problem is,
Please let me know your thoughts on how to deal with this issue, thanks!

Posted (edited)
50 minutes ago, Biran Gould said:

I was initially thinking of tracking the week number

weekNumber = (llGetUnixTime()+offset)/numberOfSecondsInAWeek ;

If offset is 0, that splits the week between Wednesday and Thursday, so you'll want it to be 3 or 4 days of seconds depending on if you want to split between sat/sun or between sun/mon.

P.S. "midnight" always confuses me. I appreciate it when dates are advertised as 11:59PM for clarity, but that's just me.

Edited by Quistess Alpha
  • Like 1
Posted

Thanks Tessa.

I think i'm going to go with

        integer numberOfSecondsInAWeek = 604800;
        integer weekNumber = ((llGetUnixTime()+offset)/numberOfSecondsInAWeek) - 2816;

so at least my weekNumber will be accurate for the rest of the year.

Maybe i'll add something like

        weekNumber = llList2Integer([weekNumber,weekNumber-52], weekNumber > 52);

to keep the value correct for next year too.

Posted
1 hour ago, Biran Gould said:

Maybe i'll add something like

        weekNumber = llList2Integer([weekNumber,weekNumber-52], weekNumber > 52);

to keep the value correct for next year too.

or just weekNumber = weekNumber%52;

  • Thanks 1
Posted
17 hours ago, Biran Gould said:

So, i have a simple HUD game, that allows the players to collect points.
But i want the HUD to reset the points to zero, at midnight on Sunday ( SL time )
and i also need to take care of people who were offline sunday, and don't come back until later in the week.
 
I was initially thinking of tracking the week number, but unfortunately, i found nothing in the date libraries for generating that from a unix time

But i'm really not sure what the best way to approach this problem is,
Please let me know your thoughts on how to deal with this issue, thanks!

Careful!  Time is a lot more tricky than you might think.  I mean, if it's just for an SL game I guess it's not that critical, but time is not really a simple, linear, calculable thing.  Time changes with government policies, technical limitations, and even imperial conquests.  To really reset every Sunday night at midnight, reliably, and set that up with Unix time, you can't just calculate 52 weeks a year and be done with it.  You need to take into account daylight savings time, and leap years, and leap seconds, and then policy changes like when the pope decided to skip a year, or a month (it happens!).

Tom Scott explained all this in a video, here.  I like his conclusion:  Use an API that tells you what time it is, and count off from that to get to Sunday at midnight.  There are a lot of free time APIs you could use for this, but that's probably too much work.  If I were you, though, I would parse the time off of llGetTimestamp.  That way, the SL servers can worry about all the details of changing unix time to human time.  Then, I would set it up so that when the script resets every Sunday at midnight, it checks the time again, and restarts the countdown to midnight in one week.  Worst case scenario, you might be off by a day, for one week, if there is a leap year.  You won't have to worry about errors stacking, and eventually being off by months, after running for a few years.

 

You are about to reply to a thread that has been inactive for 79 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...