Sign In Register

How can we help you today?

Start a new topic
Answered

How to get Server Time in Cloud Code

Hi GameSpark,


I want To gift a object every hour only when player is connected. I try different solution and nothing work complete, right know I try to get the last time  user is connected but I need the Server Time to do that and I dont know how to get it  ( by the way, use client time is bad).


Thanks for the help


Best Answer

I tried this earlier, this might help you get started on this.


I see you can do your requirement in 2 ways.

1. Create a system script for "Every Hour" and check if the player is online by fetching data from SparkPlayer info.

         - I'm not sure whats the issue  you faced in this as no complete info from your question.

2. You can use Date class of Javascript. I found this class in w3Schools and tried it in cloud code, its working fine.

 

        var timeInEpoch = Date.now();
        Spark.getLog().debug("Now : " + timeInEpoch);

 Adding to these, I found ${now} and some more fields defined by GS and are handy to use in configurator (when setting attributes for Events). More info at the end of this page Default Time Expressions Supported


I wish you find success in first approach as it should work the way you think and its the right place as well to do these tasks. Let me know if I can help you more on this.


You can use Scheduler in GS.

You can see example in this link: https://docs.gamesparks.net/howtos/cloud-code-scripting/how-to-schedule-cloud-code-scripts

Answer

I tried this earlier, this might help you get started on this.


I see you can do your requirement in 2 ways.

1. Create a system script for "Every Hour" and check if the player is online by fetching data from SparkPlayer info.

         - I'm not sure whats the issue  you faced in this as no complete info from your question.

2. You can use Date class of Javascript. I found this class in w3Schools and tried it in cloud code, its working fine.

 

        var timeInEpoch = Date.now();
        Spark.getLog().debug("Now : " + timeInEpoch);

 Adding to these, I found ${now} and some more fields defined by GS and are handy to use in configurator (when setting attributes for Events). More info at the end of this page Default Time Expressions Supported


I wish you find success in first approach as it should work the way you think and its the right place as well to do these tasks. Let me know if I can help you more on this.

Thank to all,


Is a combination of the GS Scheduler and Date.now().


I think will be work :)

It work Thanks to all