How do I sync with a server

Get help using Construct 2

Post » Wed Aug 23, 2017 3:24 pm

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?
B
10
S
2
Posts: 81
Reputation: 997

Post » Wed Aug 23, 2017 4:50 pm

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

Make a php file on your server.
Code: Select all
<?php
$t=time();
echo($t);
?>

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.
B
17
S
3
Posts: 74
Reputation: 1,088

Post » Thu Aug 24, 2017 1:49 pm

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
B
10
S
2
Posts: 81
Reputation: 997

Post » Thu Aug 24, 2017 3:16 pm

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
B
17
S
3
Posts: 74
Reputation: 1,088


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 5 guests