Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: Fri Jun 10, 2022 4:58 pm   

Reset Variables after midnight, game time zone?
 
Hey all!

I was just trying to figure out a simple way to reset a number of variables if it is past midnight game time. (Game is on EST, I am on MDT, so 2200 local time)
I don't want to reset if its been reset in the current 24 hour cycle. (Its to track jobs that are available in the 24 hour cycle.)
I also want to reset if I'm logging in after being offline for a day (i.e. missed a cycle).

I assume I would need a variable to track the current reset date-time stamp, then feed off that. Utilizing times is one of the few areas of CMUD I'm really not familiar with right now.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 10, 2022 10:26 pm   
 
Best option for that is setting the default variable for those variables.

It already resets the values whenever the session is loaded.

And you can also reset them with the #RESET command.

Odds are there is no way to tell how long you have been offline though.

#ALARM {22:00:00} {#RESET}

Will go off at 2200 local time every day.
_________________
Discord: Shalimarwildcat
Reply with quote
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: Fri Jun 10, 2022 10:32 pm   
 
shalimar wrote:
Best option for that is setting the default variable for those variables.

It already resets the values whenever the session is loaded.

And you can also reset them with the #RESET command.

Odds are there is no way to tell how long you have been offline though.

#ALARM {22:00:00} {#RESET}

Will go off at 2200 local time every day.


For alarm, do I have to be connected or have the client open to fire?
Also, I may connect multiple times throughout the day, so I need to persist between sessions.
I'm thinking running a check at onConnect, onDisconnect, and an #ALARM for 2200.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4662
Location: Pensacola, FL, USA

PostPosted: Fri Jun 10, 2022 11:03 pm   
 
The Client needs to be open, but if you close the client, it will auto-reset when you reopen anyway, so a moot point.

Take a look at '#HELP %time' to see how you can spit out a value.
I was never good at time math either.
_________________
Discord: Shalimarwildcat
Reply with quote
JRSteensen
Novice


Joined: 27 Jul 2004
Posts: 35

PostPosted: Sat Jun 18, 2022 4:38 pm   
 
So, I wanted to close the loop on this. I found an Elapsed Minutes function on here, and I modified it to ElapsedSeconds. Then, I wrote another function to display elapsed time in a human facing format (days/hours/minute/seconds). This covers 90% of my time needs. I also do a timestamp every time I reset the tracker at midnight game time, then have an onConnect event to see if ElapsedSeconds since then is greater than 24 hours. If so, it resets. (This is alongside an alarm for realtime resets.)

Here are the two functions I made/modified:

Code:

<func name="DispElapsed" id="665">
  <value>// @ElapsedSeconds(@someSecondsVar,)
// #SAY @DispElapsed(@ElapsedSeconds(@jobTrackDB.DailyResetLast,%time("mm/dd/yyyy t:ss")))
// t1 = seconds, t2 = mode, returns days, hours, minutes, seconds.
// Example long return: "0 days, 1 hours, 29 minutes, and 29 seconds"
// Example short return: "00:01:23:33"

$days = %eval($t1/86400)
$hours = %eval($t1/3600)
$minutes = %mod($t1/60,60)
$seconds = %mod($t1,60)

//Add leading zeros as necessary. (Converts local vars from int to str)
$days = %if(%len($days)=1,%concat("0",$days),$days)
$hours = %if(%len($hours)=1,%concat("0",$hours),$hours)
$minutes = %if(%len($minutes)=1,%concat("0",$minutes),$minutes)
$seconds = %if(%len($seconds)=1,%concat("0",$seconds),$seconds)

#SWITCH ($t2)
  (0) {#return %concat($days," days, ",$hours," hours, ",$minutes," minutes, and ",$seconds," seconds")}
  ("long") {#return %concat($days," days, ",$hours," hours, ",$minutes," minutes, and ",$seconds," seconds")}
  (1) {#return %concat($days,":",$hours,":",$minutes,":",$seconds)}
  ("short") {#return %concat($days,":",$hours,":",$minutes,":",$seconds)}
  {#return %concat($days," days, ",$hours," hours, ",$minutes," minutes, and ",$seconds," seconds")}
 
</value>
  <arglist>$t1,$t2</arglist>
</func>


Code:

<func name="ElapsedSeconds" id="664">
  <value>// @ElapsedSeconds(%time("mm/dd/yyyy t:ss"),%time("mm/dd/yyyy t:ss"))
// Subtracts t2 from t1, returns as seconds.

#return {%mss("(Date.parse('"$t2"')"-"Date.parse('"$t1"'))/1000","JScript")}</value>
  <arglist>$t1,$t2</arglist>
</func>
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net