troy_mccormick Posted July 30, 2008 Share Posted July 30, 2008 I'm creating a game and I'm trying to accomplish a task that has been plaguing me for some time. Here is what I would like to do: Each user has x amount of time to perform their action. If, after that amount of time, the user hasn't made an action, I would like to automatically perform the action for them. How would I accomplish this with code? What I have tried to do in the past is as follows: 1. On pinging the server, if a player finds a user to have used up the allotted time to perform an action, this user will send the action command automatically. The issue I've run into using this method is that I have received multiple actions for the auto-action player as multiple players are pinging the server every second... 2. Using the last player to have an action submitted to the server, perform the auto-action. The issue with this method is that if the user gets disconnected or whatever after they post their action, the server will be at a stand still. So how would you go about getting this done? Thanks, Troy Quote Link to comment Share on other sites More sharing options...
troy_mccormick Posted July 30, 2008 Author Share Posted July 30, 2008 In looking over the net, I'm not even finding anything useful... Does anyone have anything on this?? Past experience...experience in a different programming language...anything?!?! Quote Link to comment Share on other sites More sharing options...
revraz Posted July 30, 2008 Share Posted July 30, 2008 You should probably look into Javascript for this. Quote Link to comment Share on other sites More sharing options...
php_dave Posted July 30, 2008 Share Posted July 30, 2008 How do you identify the players that are out of time? Is it stored in a Session or in a DB? Could you not write a script that is fired on the server side to sweep through and play the actions for all the users that are out of time? Quote Link to comment Share on other sites More sharing options...
troy_mccormick Posted August 5, 2008 Author Share Posted August 5, 2008 How do you identify the players that are out of time? Is it stored in a Session or in a DB? Could you not write a script that is fired on the server side to sweep through and play the actions for all the users that are out of time? That script would have to run every second...is that really acceptable? revraz...how would javascript help with this? Quote Link to comment Share on other sites More sharing options...
Stooney Posted August 5, 2008 Share Posted August 5, 2008 I agree with revraz. Use javascript to send the action command after x amount of time given an action has not already been made. Depending on how your system is set up, you could use ajax if needed. Quote Link to comment Share on other sites More sharing options...
rawb Posted August 6, 2008 Share Posted August 6, 2008 Without javascript there is no way (that I know of) to send a request from a client to the server to do anything after a certain amount of time. Ways that I can think of to accomplish your goal: 1) use javascript to time the player on the client side and send an ajax request to update whatever needs to be updated in your database after a specified amount of time 2) use a meta refresh tag (or javascript) to time the player on the client side and refresh the page after a specified amount of time.. when the page reloads check to see if the user had run out of time on the previous page and if so update whatever needs to be updated if the user has run out of time 3) php_dave's recommendation of using a cron job to update all records on the server every so often should work 4) you can use php to check and see the amount of time the user was on the previous page and then check to see if it was too long, but this requires action on the user's part so it isn't really automatic... unless used in conjunction with option #2 I guess hope this helps a little Quote Link to comment Share on other sites More sharing options...
discomatt Posted August 6, 2008 Share Posted August 6, 2008 Cron job every 5 seconds or so. If you need responses form your users every second, I suggest using something other that HTTP/PHP to code your game. People still use 56k out there. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.