Turns in Game question.

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
timmymyrs
Posts: 8
Joined: Thu Oct 15, 2009 6:20 am

Turns in Game question.

Post by timmymyrs »

Well, I've implemented turns into my game. You get 200 turns every 24 hours, BUT, I can't figure out how I would display that somewhere. I need two LITTLE seperate tables.

Turns: ***
Reset: (Counting backwards from 24:00 hours)

Two seperate tables.

Any suggestions?

(In PHP.)
Loopy

Re: Turns in Game question.

Post by Loopy »

Depends a bit on how you've stored the time, I guess. If updates happen 24 hours from some event, you could use time() and store it in the database:

//some event took place, and cannot take place for another 24 hours. Get current time, add 24 hours, and store it in the database
$nowTime=time();
$renewalTime=$nowTime+86400;

$sql='insert into blah blah blah';


Now, when you go to update your page and either allow the person to do the event again, or tell them how long until it takes place, you just break the time down into a readable format:

//go get the time in which the update is to take place.
$sql='go get $renewalTime blah blah blah';

//get the current time
$currentTime=time();

//get the amount of time remaining between now and when the update is to take place.
$timeLeft=$renewalTime-$currentTime;

//find the number of hours that are remaining in the difference of time
$hoursLeft=floor($timeLeft/60/60);

//find the number of minutes left.
$findMinutes=$timeLeft-($hoursLeft*60*60);
$minutesLeft=floor($findMinutes/60);

//find the number of seconds
$findSeconds=$timeLeft-(($hoursLeft*60*60)+($minutesLeft*60));
$secondsLeft=floor($findSeconds);

$msg="Your turns will update in " . $hoursLeft . " hours, " . $minutesLeft . " minutes, " . $secondsLeft . " seconds.";
echo $msg;

Yields this message that updates every time on page reload: "Your turns will update in 23 hours, 59 minutes, 51 seconds."


If you're just using a cron that runs at the same time every day, then you already know the value of $renewalTime, and don't need to fetch it from mysql. However, it's important to note that cron isn't always the best idea for updating your player base. Lets say your game has been out for a year, enjoyed some success, and has 5,000 registrations. Lets say, that like most browser games, people play for a few months (if they play at all), and then go inactive. So at the year mark, out of 5,000 registrations, you might have 800 active players. If you run a cron to update turns on those players, you'll be updating the records of 4,200 people that aren't even playing your game, which of course is a waste of resources.

An alternative approach is is just to update as needed (when the user logs in, views a new page, whatever). That way, you run one update on an active user, rather than 5,000 updates on 4,200 inactive users.
Last edited by Loopy on Tue Oct 20, 2009 5:10 pm, edited 6 times in total.
User avatar
hallsofvallhalla
Site Admin
Posts: 12031
Joined: Wed Apr 22, 2009 11:29 pm

Re: Turns in Game question.

Post by hallsofvallhalla »

thats a great way to do it.
Post Reply

Return to “Advanced Help and Support”