Getting actual time

0 favourites
  • 13 posts
From the Asset Store
Time rewind like in "Braid". Choose objects that will be affected by time rewind
  • Hi everyone. I'm wondering if it's possible to get actual world time in a game and not just the system time on someone's machine or phone. This would protect against cheating in a time based grinder game.

    Anyone have thought on how this could be done?

  • Perhaps there is some sort of plug-in or something (I didn't Check).

    I'm currently only aware of how to do it in js.

       a clock example.

    Could be more info in the JS sdk threads.

  • Look at system expressions under Time. tickcount gives you the number of ticks since the beginning of the game. You could also simply keep your own tick count in a global variable that get incremented every tick you want.

    If you prefer to get a real "time" and not just tick count, use time instead of tickcount or keep a count of all dt in a global variable.

  • I'm pretty sure mhgames is looking for a way to pull real-world time into the game using a source other than the player's device.

    Is it possible? Yes, but there's no simple way to do it from within the editor (unless someone's created a plug-in to do it). You'll need an external source containing the current date/time, and a method of pulling that data into the game at runtime.

    There could very well be an easier method, but one option would be to set up a webpage using PHP to produce the current date/time, and using an AJAX request to pull that data into the game.

  • I don't think you need to fetch the real time from a remote server to actually prevent cheating. And for a time based game, the latency caused by the process of retrieving time from an external source usually is a no go.

    Best to stick to tickcount and "dt count"... Not cheat-proof, but anyway, what is cheat-proof nowadays ? <img src="smileys/smiley36.gif" border="0" align="middle" />

  • Magistross

    You could very well be right about preventing cheating using other methods, but it really depends on the game.

    Regarding latency, I didn't mean to suggest using AJAX server requests to constantly determine the in-game date/time. I was more thinking along the lines of a single AJAX request to determine the date/time upon loading finished or on the start of the first layout, and syncing the in-game clock to the request's result. At that point, in-game mechanics can maintain the correct date/time.

  • zatyka

    Of course, repeated AJAX requests is out of question. But syncing the game clock only once upon loading is not really helping to validate a timed high-score. You need two requests, for starting time, and ending time... so twice the latency. Depending on the game need, it might not be an option.

    I guess combining both external and internal validation methods could work too. Compare external time with in-game time, and if results are too far apart (latency excluded), reject the high-score.

  • Based on the original post, I was under the impression that mhgames's goal was to ensure that a player waits for a certain amount of real-world time to elapses before an in-game action occurs (e.g. growing crops in farmville). I still believe my method would work in that capacity, thought there could be a much simpler way to do it that I'm not aware of.

  • Hmm, I thought mhgames meant players would have limited time to accomplish certain things.

    Limiting actions by a real-world time delay could still be accomplished internally, but if the wait time can be done "offline" (e.g. growing crops in farmville <img src="smileys/smiley2.gif" border="0" align="middle" />), then yes, some syncing has to be done !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I was hoping there was some way to do this too.

    Hopefully it's something that will be possible in future updates.

  • There is a way to do this, and now that I'm back at my main PC, I can show you. Here's the demo:

    Demo

    Capx

    The Capx is very simple. It ajax requests a php file that I've set up to return the current US Eastern date/time. If you have your own server set up, you can create a similar set up for your own game. Here's the code used in the php file :

    <?php

    header('Access-Control-Allow-Origin: *');

    date_default_timezone_set("America/New_York");

    $datetime=getdate();

    echo("$datetime[hours]:$datetime[minutes]:$datetime[seconds] $datetime[mon]/$datetime[mday]/$datetime[year] ");

    ?>

    I hope this helps.

  • C2 doesn't offer Clock expression until you send suggestion to Ashley.

    Besides there are 2 plugins would help you:

    http://www.scirra.com/forum/c2-plugin-clock_topic42660.html

    http://www.scirra.com/forum/plugin-system-date-and-time_topic45206.html

  • Sorry for my delayed reply. Thanks to everyone who responded for the information. And yes, I was looking for a way to get actual real world time to help with time based tasks such as Farmville and other "grinders". Pulling the time from the server via a PHP script is a great solution. Thanks again.

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