Jump to content
MakeWebGames

Recommended Posts

Posted

Hey. Ive set up timestamps on my game, but ive come accross a small problem which im not to sure now to fix. WHen a user loads the page, and noone has loaded the page in ages, it wil only update once. Whereas it should be updating however many times the update has ben missed.

For example, I have a 5 minutes timestamp. No one loads the page for 30 minutes. then someone does load the page, it only updates once instead of updating 6 times.

He is my code for 5 minutes:

 

// 5 MINUTE TIME STAMPS!!!!!!

$updates_sql = $db->query("SELECT * FROM `updates` WHERE `name` = 'fivemin'");
while ($line = mysql_fetch_array($updates_sql)) {
$update = $line['lastdone'];
}
$timesinceupdate = time() - $update;
if ($timesinceupdate>=300) {
$num_updates = floor($timesinceupdate / 300);

*** MYSQL QUERY'S HERE

$thetime = time();
$result2 = $db->query("UPDATE `updates` SET `lastdone` = '".$thetime."' WHERE `name` = 'fivemin'");
$leftovertime = $timesinceupdate - (floor($timesinceupdate / 300) * 300);
if ($leftovertime>0) {
	$newupdate =  time() - $leftovertime;
	$setleftovertime = $db->query("UPDATE `updates` SET `lastdone` = '".$newupdate."' WHERE `name` = 'fivemin'");
}


// 5 MINUTE TIME STAPS DONE!!!!

 

^^ thats not the full file, but all the timestamps parts.

If someone could help me then I would greatly appreciate it!

Posted
$num_updates = floor($timesinceupdate / 300);

 

That is the part that tells how many times it should be updated..if 30 minutes has passed since last update then $num_updates will equal 6..

So you can simply multiply the updates by this..

such as :

 

$ENERGYGAIN=(energy * .10) * $num_updates;

 

Hope that helps you :)

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...