Author Topic: Database or No Database  (Read 1251 times)

Offline Shrapnel

  • Level 9
  • *
  • Posts: 46
  • Reputation: +0/-0
    • View Profile
Database or No Database
« on: June 17, 2010, 08:18:56 AM »
I'm thinking of creating some small tools to help assist with a game I'm currently playing.  An example would be a resource calculator which is a tool that would tell people how much building a certain amount of units would cost them.  I would be dealing with a small dataset and I'm wondering wheter to use php or just javascript and whether to use a database or just hard code everything.  The developers are active in making improvements to the game, so the dataset could change in the future.  My question is what are the pros and cons of the two approaches and when is it appropriate to use a database or to use static variables?
"Never compromise. Not even in the face of Armageddon" -Rorschach, Watchmen (2009)

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Database or No Database
« Reply #1 on: June 17, 2010, 08:59:20 AM »
The decision should (in most cases) be driven by where is the data stored? In your case, the cost for the units would almost certainly be stored in the database so your calculator should read the values from the database. This way you don't need to change your calculator if they change unit costs around.

Remember, machine time is cheap; human time is costly.

The pros of using static variables in this case is that it would allow you less database accesses (machine time gain).

The cons of using static variables would be that if the dataset changes then you would need to go and physically change the data values (human time loss).
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: Database or No Database
« Reply #2 on: June 17, 2010, 10:48:58 AM »
If they are actively developing it the odds are they might change not only dataset but formula as well (at least that's what I do). In such case hardcoded seems the most logical.
If there is a lot of data you might make an ".ini" file with the data, or XML.
Using database in this particular case is probably not justified.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Database or No Database
« Reply #3 on: June 17, 2010, 11:52:09 AM »
The formula is likely to be a function call... in this manner, you just use the same function call in the calculator... Again, hard-coded values would be a waste.

Upon thinking of it... your calculator really sounds like it would just be another interface to the underlying function that's already in the game. Basically instead of other code passing variables to the game function to calculate a cost, you'd be allowing the end user to specify the parameters and pass them in via AJAX, POST request, or whatever you decide to go with.

The point is... you shouldn't need to re-declare logic that already exists elsewhere in the program.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: Database or No Database
« Reply #4 on: June 17, 2010, 02:04:16 PM »
The post sounds like he is not a game dev but a player. And he is making a fan tool to help play the game, not improving the game. That's why he can not use AJAX, the game would not respond, he also does not have direct access to the function and need to emulate everything.

Offline Shrapnel

  • Level 9
  • *
  • Posts: 46
  • Reputation: +0/-0
    • View Profile
Re: Database or No Database
« Reply #5 on: June 17, 2010, 02:17:01 PM »
Chris is right, I'm just a player and I will be creating a fansite to help newbies out.  I don't have any access to game logic.  Sorry I didn't make that clearer. 
"Never compromise. Not even in the face of Armageddon" -Rorschach, Watchmen (2009)

Offline Harkins

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: Database or No Database
« Reply #6 on: June 17, 2010, 02:34:39 PM »
I'd be tempted to make a GreaseMonkey script. You can have a superior UI (integrated right into the game itself!) and scrape numbers right off the page live. Anything you can't scrape, yeah, you'd have to hardcode and update the script. (And check out some other scripts like the YouTube AutoBuffer and HD to see how they check for and prompt users to install new versions.)

Visit #bbg on irc.freenode.net to talk browser games anytime.

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: Database or No Database
« Reply #7 on: June 17, 2010, 02:48:49 PM »
But check ToS of your game first, on my games GreaseMonkey = account deleted :)

Offline Harkins

  • Level 28
  • **
  • Posts: 420
  • Reputation: +11/-2
  • Coder, blogger, entrepreneur.
    • View Profile
    • Push CX - Blog
Re: Database or No Database
« Reply #8 on: June 17, 2010, 04:39:02 PM »
How do you investigate and enforce that rule?

Visit #bbg on irc.freenode.net to talk browser games anytime.

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Database or No Database
« Reply #9 on: June 17, 2010, 05:21:36 PM »
Chris is right, I'm just a player and I will be creating a fansite to help newbies out.  I don't have any access to game logic.  Sorry I didn't make that clearer.

Ah, well that makes a very big difference then! lol Have you tried approaching the game's developers with your intent? If you're making a fansite and they're a pbbg, they might be tempted to work with you to develop it because it would be positive public relations for them which might lead to more players.

Otherwise... manually maintaining that data yourself is likely the only option available to you.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline Sagefire135

  • Level 14
  • *
  • Posts: 107
  • Reputation: +2/-0
    • View Profile
Re: Database or No Database
« Reply #10 on: June 17, 2010, 05:55:15 PM »
One possible solution would be to create an excel spreadsheet. you can have cells that hold all the numbers you would be changing, and then you can have the cells referenced elsewhere and output your php code. then you can just copy/paste into the webpage.

A1  archer(s)
A2  barracks
A3  1000
A4  10
concatenate("echo 'The cost of training ", A4," ", A1," from your ", A2, " is ", A3*A4 , " gold';")

That would obviously give you echo 'The cost of training 10 archer(s) from your barracks is 10000 gold';. if you do that for everything, you can just paste the whole spreadsheet into your php file and be good to go. you would still have to manually change numbers as needed, but the numbers would all be in the same place and only have to changed once instead of hunting for every place its used. If you are skilled with excel, you could even set it up so that when you copy part of the website (the list of units and their costs for instance) and past that into the right cells, the costs are all replaced automatically for you and you wouldnt even need to change it by hand.

I did this for a game i played, and it works pretty nicely.
« Last Edit: June 17, 2010, 06:00:29 PM by Sagefire135 »

Offline Chris

  • Game Owner
  • Level 35
  • *
  • Posts: 2,134
  • Reputation: +26/-1
    • View Profile
Re: Database or No Database
« Reply #11 on: June 18, 2010, 03:44:44 AM »
How do you investigate and enforce that rule?
Classified information :)
Take a note that game devs can google too, so they already know every line of your script while you don't know every line of the game script.

Quote
One possible solution would be to create an excel spreadsheet.
CSV works fine with excel, probably the best solution in your case if you want to make it in PHP.

Excel sheets are probably the most popular, at least that's what players in my games make the most often.

 


SimplePortal 2.3.3 © 2008-2010, SimplePortal