How do I sync with a server

0 favourites
  • 4 posts
From the Asset Store
Create your own wss server and ws server with ssl and without ssl.
  • Hello,

    I was wondering if it's possible to run a construct 2 build on a server where the system clock can be synced to the game clock.

    To illustrate, let's say the construct 2 build has a day night cycle synced to real time, so anyone who visits the server and plays the game will notice that the game is taking on the servers clock to set the day/night phase.

    I was looking into rex's timeline plugin https://rexrainbow.github.io/C2RexDoc/c2rexpluginsACE/plugin_rex_timeline.html

    but I am curious how others might go about this or if I'm on the right track?

  • Well, you can do that pretty easy without any plugins.

    Make a php file on your server.

    <?php
    $t=time();
    echo($t);
    ?>[/code:8bui4z18]
    This will output the unix timestamp. You can then convert the timestamp using "date()" (Refer to this for how to do it:
     (php.net/manual/en/function.date.php)
    
    Then request the file via AJAX. Using AJAX.LastData gives you the output of the php file. Then you just have to compare the result to whatever you consider day or nighttime. Don´t forget there are timezones and it´s not everywhere day or night    not sure if that matters for you though.
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hey! Thank you for your reply

    I've set up the php file and served it but I can't seem to get it to retrieve in Construct

    I'm wondering if it's because I'm running Construct locally

    link to screenshots

    http://imgur.com/a/jSITG

    I've split the event sheets so that a request is made before going to the new layout, and I removed the every 5 seconds update.

    Add an Ajax - On Completed event but still comes out to daynightOutput = NaN

  • I suppose that´s because you have to wait for the ajax request to complete. There´s the "On ajax completed" trigger, inside there you then can use the AJAX.lastdata

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