Lua Table with multiple dimensions for a card game

I want to create a table of all of the cards available. Here we see an example of 2 such cards:

cardPool[1][name] = "Wrath"
cardPool[1][crystal_cost] = 0
cardPool[1][destroy_opponent] = 25
cardPool[1][destroy_you] = 0
cardPool[1][heal_opponent] = 0
cardPool[1][heal_you] = 0

cardPool[2][name] = "Glory"
cardPool[2][crystal_cost] = 8
cardPool[2][destroy_opponent] = 0
cardPool[2][destroy_you] = 0
cardPool[2][heal_opponent] = 0
cardPool[2][heal_you] = 25

The grand goal is to store these cards in a MySQL DB on a back-end and each time the game starts i want to download it through web-service as a JSON and translate it to a table like you see above.

What would be the best way to structure the table so that i can have an infinite number of cards each with attributes like that?

The code looks a bit weird. I’d probably define the cards like this:

cardPool[1] = {
	name = "Wrath",
	crystal_cost = 0,
	destroy_opponent = 25,
	destroy_you = 0,
	heal_opponent = 0,
	heal_you = 0,
}

This structure would immediately translate into JSON:

[
   {
      "destroy_you":0,
      "heal_opponent":0,
      "heal_you":0,
      "crystal_cost":0,
      "name":"Wrath",
      "destroy_opponent":25
   }
]
4 Likes