February 21st, 2007, 10:08 AM
Online Game - Quick PHP/MySQL Question
I am quite desperate for help with this small PHP problem!
I am creating an online game in PHP and have almost completed the script, although there are a few small things that I just can't seem to figure out.
Within the game each user has a character, which is interactive (can be fed, played with, etc). Each character has it's own statistics (Hunger, Intelligence...).
I have written the script that updates these stats if the user interacts with their character (feeds it) and that works great, but now I need to write the script that depreciates the stats regularly without the user logging in.
To simplify, if the user does not log in for two weeks, their character will grow more and more hungry each day until it is starving.
If anyone has any ideas on the best way to write this in php then I would be extremely grateful.
I hope this makes sense...
Thanks in advance,
February 21st, 2007, 10:27 AM
don't know exactly how to do them but could set up a cron job to run each day that does what you want. it can run a script to do this.
or have a DB table that holds the last they feed their character and when they log back on update it then.
February 21st, 2007, 11:52 AM
Thankyou for this - these are great ideas...you know what it's like when the answer is obvious but you have a coding overload...
Originally Posted by twistedtwig
February 22nd, 2007, 06:21 AM
you need a field in the database that records each time the user logs in
then you need a php script to check if the user log in time is a long time ago(ask for help in php forum) and if so, increase their hunger etc
July 19th, 2007, 08:56 AM
August 12th, 2007, 08:41 PM
For what he is asking doing it in PHP and then setting it up as a cron job would be the best thing. Unless you know another language like java or perl you could write a script to continually check, or just as a cron job.
Don't forget you need to think about the future, so if you were to run checks on all your users through accessing a certain page it may time out or generate errors if you had tons of users. Or what happens if you go on vacation or get sick for a couple weeks? Then the "automation" won't happen.
We Live; We Love. We Hate; We Die.