building time count

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
ZetCoby
Posts: 2
Joined: Sun Jun 03, 2012 7:37 am

building time count

Post by ZetCoby »

hi guys i have a question. how do i make a time count in a game when a player creates a building? i wanna show the player how much time it takes until the building is finished, i wanna show it in real time so the player can see the time going down.
i wanna know what exactly i need to use to acomplish this? and how do i make it so if the players closes the browser and lets say he comes back after 5 houres and enters the game he can see the time that has passed, do i need to memorate the time somewhere until he logs in again? do i need to combine javascript with php? do i need a database at this? i really have no idea, and could not find any tut on this :(... do u guys know any tutorials for this? or can someone explain me ? please help me
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: building time count

Post by Jackolantern »

I believe Halls has a tutorial about this somewhere, but he will have to chime in on where it is exactly, but it would take all of the above: PHP, Javascript and a database. The real-time countdown would have to be done with Javascript since that is the main way you show real-time animations. However, the JS countdown animation is just for the player's reference, and is not what is enforcing it. What actually would be enforcing the countdown is PHP referencing the time the countdown started from the database. When a player starts building, you would need to use PHP to add the time to a special table in the database, and then anytime the player tries to do something else (say they pull another page up from their browser history or just try to do something else), check to see if they are in that table, and if they are they must still be in a building countdown. Compare the current time to the time in the database record, and use the time difference to recreate the Javascript countdown timer with maybe a message telling them they can't do that yet because they have X time until building is complete. Or, if you don't want to stop them from doing other things, you could simply add the JS timer on a sidebar of the page so they can keep tabs on how the building process is going.

Hope this helps until Halls can advise you on where in his tutorials the JS countdown is :)
The indelible lord of tl;dr
ZetCoby
Posts: 2
Joined: Sun Jun 03, 2012 7:37 am

Re: building time count

Post by ZetCoby »

thank you for the ideas, i will go search again to see if i have any luck now to find a tutorial xD
hope halls will visit this topic soon :D
User avatar
Foofighter
Posts: 121
Joined: Sun Mar 04, 2012 1:52 pm

Re: building time count

Post by Foofighter »

Post Reply

Return to “Beginner Help and Support”