Expected ")" near "=" when creating a table

I am trying to make a simple table but I cant get that right.

Its a server side script:

proptable = {}
function addNewPropToTable(ply,model,ent)
	table.insert(proptable,ply = entity);	


hook.Add("PlayerSpawnedProp", "addNewPropToTable",addNewPropToTable);

Why does this produce errors? Even if I move proptable = {} inside the function its still the same error?


table.insert is only for sequential tables. If you want to set the key you need to do:

tbl[key] = value

What’s with the ‘ply = entity’ as the second argument?

Thanks! That fixed it

[editline]24th September 2017[/editline]

Me not knowing how tables work

To add to this, that formatting/logic is kinda fucky.

For future reference, using semi-colons doesn’t do anything in Lua.
You can also simplify your hook additions like so:

proptable = {}

hook.Add("PlayerSpawnedProp", "PlayerSpawnedProp.AddPropTable", function( _Player, _Model, _Entity )
	proptable[_Player] = _Entity	

Honestly, sticking everything togheter like this, seems to be, at least for me, less readable with no real performance boost. I like to keep things that belong togheter (hook and function) while still having a seperate function block for easy reading.

Thats personal preference tho.

Also whats “funky” about the logic? Its literally just some test example I came up with.

At least gotta make stuff local.

[lua]local proptable = {}
local function addNewPropToTable(ply,model,ent)
– …[/lua]

table.insert(proptable,ply = entity);

would have caused an error, but it looks like you already realize that.
And yeah, if you are only using it in that file; do what NeatNit said and localize it.