Worqy Posted October 16, 2010 Share Posted October 16, 2010 Hi! I have a question that I need help with. I guess almost everyone of us have played a webgame where something happends automaticly. Some examples: Attacks, resources in Travian, Tribalwars, Khan Wars ... How are these things done? Now I'm talking about automatical things that happends every second. Is there a Cron Job that every second connectes to a database and adds more resources to the player? Regards Worqy Quote Link to comment Share on other sites More sharing options...
Worqy Posted October 17, 2010 Author Share Posted October 17, 2010 Bump Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted October 17, 2010 Share Posted October 17, 2010 Depends on what you are talking about because you didnt give much specifics. Most web based games are developed in flash or java, which would be different from using php to build a game. If you are using php/javascript to build a game then it can vary depending on what you mean. If you mean the game updating while the player is on the page then they are probably using ajax to send requests to update the player info. If you mean updating the players data while they are not on the page then more than likely they are using a cron job that runs that will update the player information while they are not there. I wouldnt run a cron job every second but more likely it will run every 15 mins or so. Quote Link to comment Share on other sites More sharing options...
Worqy Posted October 18, 2010 Author Share Posted October 18, 2010 I mean webgames made in PHP. And Yes, the stuff updates when the player is online and when hes not. I'm just wondering how they are doing it, because having a cron job update a database every second sounds too much. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted October 18, 2010 Share Posted October 18, 2010 you do not want to run a cron job every second, if there is any way to avoid it. aside from the potential server load, you can't be sure the previous run is complete before the next one, and the next one, and the next one. things like you're talking about are most likely done with database triggers: if x happens, then update y and z. Quote Link to comment Share on other sites More sharing options...
Worqy Posted October 18, 2010 Author Share Posted October 18, 2010 I can explain how a example game would work. The player logs in to the account and build a build that gives him 6400 resources every hour. Then the player logs out. Now after one minute 1 resource shall be added to the database value. Now the player logs in again and upgrades the building so it gives him 12800 resources every hour. And the player logs off. Now every 30sec the program must add 1 resource to the database. And lets say that there is 3 players in the game. One shall have the resources at 00:00:00 (Midnight) another one at 00:0045 and the third one at 00:01:3. And when there is even more players the resources must be added every second. Without the player doing nothing. He/She does not even need to be online (logged in). Now I would wan't to know how this system is done? Quote Link to comment Share on other sites More sharing options...
Worqy Posted October 19, 2010 Author Share Posted October 19, 2010 Nobody that can help me? 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.