Jump to content

Logic Question... RE: Game Programming


troy_mccormick

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.