Table becomes nil after restart?

Here’s what i’m working on. The table becomes nil after restarting.
Could someone explain to me how I would initialize this properly?

Sample:



cg = 
{
	p1 = { value },
	p2 = { value },
	design = 
		{
		SizeW = 150,
		SizeH = 250
		},
	pos = 
		{
		
		card1 = 
			{
			
			x = ( ScrW() /2 ) - ( cg.design.SizeW /2 ),
			y = ( ScrH() /2 ) - ( cg.design.SizeH /2 ),
			valuePosX = ( cg.pos.card1.x + ( cg.design.SizeW /2 ) ),
			valuePosY = ( cg.pos.card1.y + ( cg.design.SizeH /2 ) ) + 50,
			
			
			},
			
		card2 = 
			{
			
			x = ( ScrW() /2 ) - ( cg.design.SizeW /2 ),
			y = ( ScrH() /2 ) - ( cg.design.SizeH /2 ),
			valuePosX = ( cg.pos.card2.x + ( cg.design.SizeW /2 ) ),
			valuePosY = ( cg.pos.card2.y + ( cg.design.SizeH /2 ) ) + 50,
			
			
			}
		
		}
}


After map restart, you have to rerun the whole code. Are you sure the table gets ran earlier than the code itself? Are you sure you are running both codes on client?

Is that table in the same file that’s erroring? Which is being ran first?

I’m starting up a singleplayer server and running this code clientside.

[editline]5th November 2015[/editline]

I think the table doesn’t recognize that value because that variable isn’t defined yet.

I’ll have to create the tables and add the values in another step. But, is there
a better way to do this? I wanted everything tucked into a single table

Your problem is that you are initializing cg and using its value when it is not initialized. Replace the cg.design and cg.pos with values or initialize every var in a order.

I think something like this would fix it, if not already done:



cg = {}

cg.table = {
cg.pos,
cg.design
etc
}


[lua]cg = cg or {}[/lua]
for autorefresh unless you want to rebuild the table every time babe