How do i know what time is it in real time?

  • I know that i can use the plugin browser to retrieve this information but the user could just change the time on his phone and get advantage of it. I don't know how to use database i am trying to learn it but, is there any easy way or something that you can send me tutorial on to do this thing?

  • There are a number of 'tricks' you can use to determine if the date time has changed, like saving the date time to local storage the first time the app is run. The next time it's run, check to see if the current date is later than the previously stored one and if so, update it. You could also have periodic checks throughout the game to see if it's changed.

    If you're really concerned they may change it your best option is to get the time from a server using AJAX and compare it to the browser time.

    Here's a quick project I slapped together to get the time from worldclockapi.com

    + System: On start of layout

    -> AJAX: Request "http://worldclockapi.com/api/json/utc/now" (tag "time")

    + AJAX: On "time" completed

    -> JSON: Parse JSON string AJAX.LastData

    + AJAX: On "time" error

    -> (no actions)

    + JSON: Has key "currentDateTime"

    -> Text: Set text to JSON.Get("currentDateTime")

    It does get and display the proper time but, because it's a http and not a https, Chrome initially blocks the AJAX request. You have to click on the 'shield' to allow unsafe website requests. But, it shows you how it could be done.

    Ultimately though, if they really, really want to cheat by changing the system time, they will. You just need to find ways to make it difficult.

  • Thanks for your answer but when I use worldclockapi.com/api/json/utc/now it gives me 0

  • Well, if you click on that link that you posted, you'll see that it's display's a JSON so, if you're using that URL, it's definitely not a 0.

    If you run in debug mode, what's loaded into the Ajax.LastData?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I will check after, do you know what url i have to use to get as answer from the site the week day?

  • JSON: Has key "dayOfTheWeek"

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)