Jump to content

Need help with a complex PHP code


Pi_Mastuh

Recommended Posts

I'm making a virtual pet site of sorts. I have the hunger of the pets stored as an integer 1 - 5. I need to make it increase by 1 every 24 hours or so. Then I need to make a list box that drops down with the number of pets the user has, with each one as an option. Then when you click on the pet, it gets rid of the food item associated with the list box and decreases the pet's hunger by 1. I have no idea how to do that though, does anyone know how I could do this? I don't know where to start...

Thanks!  :D
Link to comment
Share on other sites

That's about several hundred questions, so I'll give you a starter on the 'every 24 hours' part.  Check you web host server control panel to see if/how a cron task can be run.  Cron tasks can be automatically scheduled to run at any recurring time you want.  If you are unfortunate enough to be running on a Windoze server, you'll need to look at the scheduler (whatever they call it) for the same functionality.
Link to comment
Share on other sites

An alternative methode of doing this would just having it check at the beginning of a show hunger request. Have something like...

$var = current time (in seconds) - time last fed (in seconds);
$lost_hunger = floor($var/(60*60*24));

if ($lost_hunger > $hunger_left) $pet = dead!;

then subtract that from the current hunger


Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.