Best way to save owned towers?

Hi,
I’m not really sure if this is the right place to put this but here goes. Note that I HAVE NOT added this yet into the game.
I’m making a tower defense game, and in a tower defense game you purchase towers that you keep forever. How would one go about saving which towers they have? It would be quite tedious to have a save for each tower that they own. I was thinking of a string, containing the IDs of a towers that they own. For example “aa” is the first tower, “ab” is the second tower, etc. The decoder would split the string into substrings, each with 2 letters, and that would the be towers that they own. I can’t think of any potential issues with this method, and I’d like to know:

  • if there are any issues
  • if there is a easier / better / faster / more elegant way to do this.
    Thank you.

Usually, in my games where there are a ton of different items, in your case towers. I assign an ID to each item, making it extremely easy to save data.

Example:

local Towers = {
	["Tower1"] = 1,
	["Tower2"] = 2
}

Using this you can have their data looking like this

local OwnedTowers = {1, 152, 52}

super easy to expand and modify

Great, thanks a lot. I might stick with letters instead of numbers, because you can only have 100 numerical tower IDs that are 2 digit and you can have 676 alphabetical tower IDs that are 2 digit.

1 Like