Author Topic: Managing the auto-incrementing of resources in games  (Read 1013 times)

Offline Dart

  • Level 1
  • *
  • Posts: 2
  • Reputation: +0/-0
    • View Profile
Managing the auto-incrementing of resources in games
« on: February 11, 2010, 03:54:02 PM »
Hello,
first of all, congrats on the site and the community, it's a great deal of help ;)
I was wondering, what is the most efficient way to deal with the auto-incrementing of resources in, like, strategy games? Or, similarly, health in some other rpg games?
For example, gold may be incremented by 1 unit every 2 seconds. It seems a bit silly to me, to have a script running that every 2 seconds increments the gold of ALL players in the database by 1 unit. Besides the fact that I can't think of a way to have a script constantly running (talking about PHP with MySQL on Unix), i think that it would be very memory-cpu consuming to do so. But I can't think of any other way to do it.
So, do you know any better way to achieve the goal?
Thanks in advance.

Offline Nox

  • Level 35
  • **
  • Posts: 738
  • Reputation: +12/-2
    • View Profile
Re: Managing the auto-incrementing of resources in games
« Reply #1 on: February 11, 2010, 04:08:59 PM »
Here's a quite in-depth thread for you http://community.bbgamezone.net/index.php/topic,1815.0.html :)

Basicly it IMHO depends on how many players you expect, how frequent update is and how frequently accessed are pages that need to know a value for certain player(s) it may or may not be beneficial to use cron

If you expect many players, updated not so often but the values are needed frequently then that it a perfect situation for cron.
If you expect frequent updates and they're not needed so much, here's a great case for on-view update (update is triggered by player visiting the site that needs the value)
Etc.
Meet us at an IRC irc.freenode.net #bbg as well
Enjoy http://spiritbeacon.noxart.cz/ !

Offline jannesiera

  • Level 35
  • **
  • Posts: 1,026
  • Reputation: +6/-1
    • View Profile
    • BBGameDesign
Re: Managing the auto-incrementing of resources in games
« Reply #2 on: February 12, 2010, 10:07:12 AM »
If you are updating every second obviously you should not use cron. In many "normal" browser based games it's not a good iea to use cron but rather to use timestamp comparisons. There have been several discussions about this, so you can always use the forum's search function.

Offline Dart

  • Level 1
  • *
  • Posts: 2
  • Reputation: +0/-0
    • View Profile
Re: Managing the auto-incrementing of resources in games
« Reply #3 on: February 12, 2010, 12:04:05 PM »
Thanks guys for the replies, I checked out also the topic that Nox suggested and now all of my questions on the specific subject are solved.
Thanks for the help!  ;D

Offline Hawkins

  • Level 7
  • *
  • Posts: 35
  • Reputation: +0/-0
    • View Profile
    • Indie Resource
Re: Managing the auto-incrementing of resources in games
« Reply #4 on: March 10, 2010, 03:45:22 PM »
if you mean autoincrementing in the database I have never heard of that I only ai for the id's of items players locations shops for rpgs but have never seen it used on say a resource count before

Offline dsheroh

  • Level 21
  • *
  • Posts: 235
  • Reputation: +6/-0
  • Perl Vicar
    • View Profile
    • Psi Rangers
Re: Managing the auto-incrementing of resources in games
« Reply #5 on: March 10, 2010, 04:50:39 PM »
if you mean autoincrementing in the database I have never heard of that I only ai for the id's of items players locations shops for rpgs but have never seen it used on say a resource count before
The topic in this discussion wasn't about autoincrement/serial fields of the type typically used for record ids in databases.  It was about automatically handling periodic resource production.  e.g., "Every hour, add 10 gold to the player's treasury." or "Heal 1 health per minute."

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal