- Home /
How to generate a random seed at a 24 hour interval
Hello!
My game is played locally and I can generate a map with a random seed value. I want my users to all have the same seed and after 24 hours the seed changes. So that everybody can play the same map and send in their high scores. How can i randomize a seed every 24 hours? How do i make sure that different time zones still apply to the 24 hour seed?
I do not have a server or something similar that can run and change the seed. The game is only played locally on the clients computer except from sending in a high score after each level.
Thanks in advance
When generating the seed, store it somewhere (file / playerprefs / ...), along the date the seed has been created.
When you must use the seed, check if it has "expired" (ie : Time.time - saveTime > 3600 * 24
)
EDIT : If all the players must play on a same map the same day, you will have to get the date from somewhere (ins$$anonymous$$d of Time.time). $$anonymous$$aybe, you can have a solution using System.DateTime.UtcNow
https://msdn.microsoft.com/en-us/library/system.datetime.utcnow(v=vs.110).aspx
Depends how much you're worried about users changing the date on their device.
using UnityEngine;
using System.Collections;
using System;
public class UTC: $$anonymous$$onoBehaviour
{
void Start()
{
print (DateTime.UtcNow);
}
}
Should show the current device date/time in UTC but it's open to exploits.
var url = "http://mytimeserver/gettime";
var dateTime : System.DateTime;
function Start () {
var www : WWW = new WWW (url);
// Wait for download to complete
yield www;
dateTime = DateTime.Parse(www.text);
}
Should work (although I googled that!) if you have a reliable time server you can request from.
Just poll the server in a Start() and have the game keep track of time from there.
$$anonymous$$inda off topic but I'd also change the tick over time for the maps, if you always start at the same time some time zones will have a natural advantage.
Answer by Eno-Khaon · Jun 06, 2016 at 08:26 PM
There's a lot of good info at Microsoft's page regarding time zones and relative time.
If you wish to make your time zone the baseline, for example, determine the time offset for it relative to UTC (the absolute baseline, in this case), then use that as the basis for a second time conversion for the player.
Your answer
Follow this Question
Related Questions
How to change perlin noise seed? 1 Answer
How to save a random seed to a playerpref 2 Answers
Set Random.seed for noise generator 1 Answer
GLSL: Get current time in millis 1 Answer
How to call a user input variable in another script. 1 Answer