Page 1 of 1

Subtables in Lua

Posted: Sat Aug 09, 2014 3:31 am
by tochy97
well i tried to create multiple sub tables at all in the same level but kept getting this error saying that the very 1st one should have a bracket to close it off even though it already has one.

Code: Select all

player = {
	x = 15,
	y = 15,
	x_velocity = 0,
	y_velocity = 0,
	speed = 500,
	health = 500,
		shotgun = {
		damage = 450,
		}
		pistol = {
		damage = 50,
		}
		sword = {
		damage = 500,
		}
		smg = {
		damage = 100,
		}
		assault = {
		damage = 200,
		}
		sniper = {
		damage = 550,
		}
}
sorry if the top explanation is a bit confusing. this isnt at all easy for me to explain. all i want is to find a way to make the player change to one of the weapons above. so using sub tables to extend the player table is what i thought would be the best idea. any help would be appreciated.

Re: Subtables in Lua

Posted: Sat Aug 09, 2014 4:38 am
by kikito
You are missing one comma after each subtable, eg:

Code: Select all

   health = 500,
      shotgun = {
      damage = 450,
      },
      pistol = {
      damage = 50,
      },
      ...

Re: Subtables in Lua

Posted: Sat Aug 09, 2014 11:06 pm
by tochy97
thanks a lot. i feel dumb for not knowing that but thanks still.