Subtables in Lua

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
tochy97
Prole
Posts: 24
Joined: Sat May 24, 2014 5:06 pm
Location: Dallas, Texas

Subtables in Lua

Post 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.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Subtables in Lua

Post by kikito »

You are missing one comma after each subtable, eg:

Code: Select all

   health = 500,
      shotgun = {
      damage = 450,
      },
      pistol = {
      damage = 50,
      },
      ...
When I write def I mean function.
User avatar
tochy97
Prole
Posts: 24
Joined: Sat May 24, 2014 5:06 pm
Location: Dallas, Texas

Re: Subtables in Lua

Post by tochy97 »

thanks a lot. i feel dumb for not knowing that but thanks still.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 5 guests