0
\$\begingroup\$

I'm working on an Android Idle game, with many items that user can buy in each level, that each of them has more than 50 levels who can be updated by the user. Each item in each specific level can produce some value of a specific unit every second in the game. Currently, I manage this massive game data (Not user's data) in the Dictionary data structure in code, that each item has an instance of Item class for the value. Item class has many properties like for example multidimensional arrays of levels data. I initialize this dictionary each time user opens the game.

The problem is we want to balance the game, and it needs to change this massive data many times for test. with the current structure, it takes hours to edit data each time.

My question is, is that a better way to manage massive items game data to can be simply replaced for example by data from an excel's sheets in Unity? Thanks.

\$\endgroup\$
  • \$\begingroup\$ I don't quite understand what you're asking. You have loads of hard coded constants and want to know how move them somehwere else to make changes easier? I would suggest using JSON, XML, or any format that suits your needs, move the data there and load them from your game. Then add some functionality to your game that allows for reloading the entire data set while ingame to quickly iterate and test out how the new values play on level X. Or even better, use formulas (RPG formulas here). \$\endgroup\$ – Ignatiamus Feb 1 at 14:36
  • 1
    \$\begingroup\$ @Ignatiamus Thanks, Yes I have loads of hard-coded constants and want to know how to move them somewhere else to make changes easier. Is that a good idea to save this massive data in JSON or XML and load them from the device? because it may add "Read from file" cost on runtime when I load data in the game. \$\endgroup\$ – user1579019 Feb 1 at 15:02
2
\$\begingroup\$

The problem you are running into is a very common one, and the reason why the software design rules around avoiding Magic Numbers and Magic Strings exist. The common solution to the problem is to move the offending value into a single location so it is easier to change. This is usually done through the use of a file for the data (constants file, config file, json file loaded at start, etc). Then, instead of referencing the value directly, your code can be updated to reference the loaded data.

Depending on how deep of a dive into Object Oriented Programming you want to do, you can drive a lot of your code through these kinds of files. A couple years ago I built out a utility for a game I was designing, and because I was still developing technologies, buildings, skills, etc for it, I wanted to make it as generic as possible. I created the basic shell for each object, and populated any important values from a file loaded at startup (for example, my code didn't know that a Barn existed, but it did know that it could have a list of buildings loaded from a file, which happened to contain a Barn object).

The more OOP you go in this way, the easier it is to change values and inputs, but the more complex the code needs to be in terms of error handling. In my example, let's say that a user's data I am loading has reference to the Research Station building, but my buildings file no longer has that building in it. I need to be able to handle that situation, however I decide is appropriate. In your scenario, what happens if you dynamically load an upgrade that has 50 levels, but when your player starts up, their save has 51 levels of upgrades for it?

I'll also add that the vast majority of idle games with upgrades use a multiplier instead of fixed pricing for their upgrades. instead of knowing the cost of each of the million upgrades, it knows that the upgrade cost is some formula like *1.07^(upgrade level) I'm not certain from your post if you are hard coding them all, or if you are using a multiplier.

\$\endgroup\$
  • \$\begingroup\$ Thanks. Yes, I received fixed data from Data Team and put it in the game. I think I should use the formula who they use to generate these numbers and generate that data on runtime in the game as you said. \$\endgroup\$ – user1579019 Feb 1 at 16:09
  • 1
    \$\begingroup\$ Good answer! And @user1579019 Go with the formula, it will save you lots of headache and if you really fear long loading times this will improve it as well (trading file size for some CPU calculation cycles). \$\endgroup\$ – Ignatiamus Feb 1 at 16:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.