Resetting Global variables daily

Hi, I’m a newbie and I am struggling to solve this problem. I have a variable “daily reward” that I want to reset to 0 every day. I followed the youtube video regarding daily events however it doesn’t seem to work in mine. Please help

You’re going to have to give more information. How are lastEventYear and lastEventDay determined?

Does this event happen once in the game? If so, why don’t you put it in a “Beginning of scene” event instead of using “Trigger Once

And how do you mean it doesn’t work? Does it set eventReady to true when it should be false? Vice versa? Or something else?

Thank you for responding. Basically the “lastEventYear” and “lastEventDay” is supposed to be temporary variables to determine if the literal next day has come.

I can claim the daily rewards fine the first time around. However, when the next day comes, the variable “daily reward” that is supposed to reset, does not. I want to reset my variables daily and I can’t figure it out

Yes, I understand that from the events. But how are they assigned a value? Can you screen shot that?

and the YouTube video I followed, they did not actually reset a global variable daily so I was experimenting on how to solve it by myself. But no luck

If there is any alternative way to adjust value of a variable daily, please teach me

Have a look at this post, where a solution was posted on checking for the time elapsed since the last reward was given.

It uses local storage to save a timestamp, and then check how man hours have passed since it was last written. This is something you should look at doing instead of using variables.

Thanks. Next question though, from the post you suggested. How does the variable “LastTimePlayed” measured or valued?

It’s measured as number value. Basically LastPlayedTime is a number value, then once the player loads back to the game it saves currently time. After that it does a calculation between when the player last loged in and after he logs in. Then he (The player) receives their reward. By the way, you will have to note that 3600000 is the time 1970.

It’s the value that’s read from the storage. And that value is the last time the game was played:

image

  • The first action retrieves the previously recorded play timestamp and puts it in LastPlayedTime.
  • The second action saves the current timestamp back to storage.
  • The third action calculates the number of hours that have passed between now and the last timestamp (take note, that last action should read “Time("timestamp")”. That same post explains why the 3600000 (and it has nothing to do with 1970 :slight_smile: ).

Hey, just a quick follow-up. So I am now trying this method, do I need to reset my variable “Elapsed Time” back to zero after getting the reward? Or do I just leave is as it is?

This is the screenshot

Also another question, does this method only count the time that the game is closed. Because in my game, my variable “daily reward” is claimed once a day. After a day has passed, I want it to reset. Now I am wondering, if I open up my game before the elapse time is 24 (when it is supposed to reset), would it rewrite the time I last used it (from when I claimed the variable daily reward)

I appreciate the help.

Ideally the load and save to storage are done at the beginning of the scene (with that condition in the event). In which case, you should make the second event a subevent of the first and then you wouldn’t need the trigger once or to reset ElapsedTime.


As it stands, yes it would. So you would need to move the save to storage into the second event, so it only gets saved when a day (or longer) has passed.

I am getting confused :frowning: is it possible to send me a screenshot of how you would do it? Thank you

Like this:

Thank you. One last question. does the variable LastPlayedTime automatically saves the current time or do I need a separate event for that?

P.S I’ll get back to you tomorrow about the progress of my problem since its a daily event.

LastPlayedTime takes whatever timestamp was last saved to storage. The saving of the current time is done in the second event, indicated by the arrow in my modified screen snip above. You won’t need any further events.

1 Like

Okay now there is a problem, I tried to see what the value of my variable elapsed time is and it shows this
image

Note: This is the first time I opened the game so there shouldnt have been any previous timestamp for it to calculate into this value. I don’t know why it shows like this

screenshot of my event:

If there’s nothing in storage, then that could be the problem. You could change it to check before trying to read from storage, defaulting to Time(“timestamp”) if it’s not there. Something like:

Okayy, but why do I need to change my variable “lastplayedtime” to timestamp?