How to properly make a config for an addon?

I have a Derma window that pops up and displays a DIconLayout.
I’m attmepting to make a config for easy editing/access.
Here is my table so far


local gamemode.ents.ShopNpc = {}

local gamemode.ents.ShopNpc = {
	--Number of panels
	NumPanels = 36;
}

However, I get this error when the table is created


[ERROR] gamemodes/gamemode/entities/entities/npc_shop/cl_init.lua:27: unexpected symbol near '.'
  1. unknown - gamemodes/gamemode/entities/entities/npc_shop/cl_init.lua:0

I access the stored info for NumPanels by using


gamemode.ents.ShopNpc.NumPanels

Thanks for you help
(this may seem like a stupid post, but i’ve barely ever used tables before, so sorry. Also, i have no idea what i’m doing with this code, but you probably already noticed)

You got this error, because table args are separated by “,” not “;”. And also, you are creating table in existing table and in this case it cant be local



// Can be local
simpleTable = {}
// Can't be
parentTable.temp = {}


You can use either one.

So, how do I do this properly. I don’t quite understand.



local gamemode = {} -- im not sure, what u want it to be local
gamemode.ents = {}
local gents = gamemode.ents -- will make code shorten?
gents.ShopNpc = {}



local gamemode.ents.ShopNpc = {}

local gamemode.ents.ShopNpc = {
	--Number of panels
	NumPanels = 36;
}

This errors because you are trying to create multiple tables without initializing them. Have a look at this:



local gamemode = {
	ents = {
		ShopNpc = {
			--Number of panels
			NumPanels = 36
	}
}


This creates the 3 tables you are looking for.
Alternatively you can do this:



local gamemode = {}
gamemode.ents = {}
gamemode.ents.ShopNpc = {}
gamemode.ents.ShopNpc.NumPanels = 36


You can get the NumPanels value with gamemode.ents.ShopNpc.NumPanels
But if you want to do it right you want to check every step.


if gamemode and gamemode.ents and gamemode.ents.ShopNpc and gamemode.ents.ShopNpc.NumPanels then
	-- do some stuff
end

This is exactly what I was looking for!