lua expected ( before [

I mean, wtf is happening



top_inventory_item_hash = {}

local function CreateitemGrid( xposition )
	LocalPlayer().TopInventoryLimit = 10
	if top_inventory_item_hash[LocalPlayer().TopInventoryLimit] != nil then
		if top_inventory_item_hash[LocalPlayer().TopInventoryLimit].ID == #top_inventory_item_hash then
			stop_rendering_item_hashes = true
			return
		end
	end
	
	top_inventory_item_hash[#top_inventory_item_hash + 1] = vgui.Create( "DModelPanel" )
	top_inventory_item_hash[#top_inventory_item_hash]:SetModel( "models/player/kleiner.mdl" )
	top_inventory_item_hash[#top_inventory_item_hash]:SetSize( xsize( 50 ), ysize( 50 ) )
	top_inventory_item_hash[#top_inventory_item_hash]:SetPos( xpos( xposition ), ypos( 30 ) )
	top_inventory_item_hash[#top_inventory_item_hash].ID = #top_inventory_item_hash
	
	function top_inventory_item_hash[#top_inventory_item_hash]:LayoutEntity( ent ) return end //THIS GIVES THIS ERROR
end


[ERROR] gamemodes/pirates/gamemode/hud/cl_hud.lua:107: ‘(’ expected near ‘[’

  1. unknown - gamemodes/pirates/gamemode/hud/cl_hud.lua:0

-snip-

Try localizing it first,



local pnl = top_inventory_item_hash[#top_inventory_item_hash]
function pnl:LayoutEntity( ent )
      return
end


You can’t define functions on an access statement like this:



function top_inventory_item_hash[#top_inventory_item_hash]:LayoutEntity( ent ) return end


Store it first (Also do this for every other call because why access the table every line; it’s slower.



local obj = top_inventory_item_hash[#top_inventory_item_hash]
-- ...
function obj:LayoutEntity( ent ) return end


it was where function pnl:LayoutEntity( ent ) was (would be in your example)

You can make the whole function more readable while you’re at it:

[lua]top_inventory_item_hash = {}

local function CreateitemGrid( xposition )
LocalPlayer().TopInventoryLimit = 10

local topitem = top_inventory_item_hash[LocalPlayer().TopInventoryLimit]
if topitem and topitem.ID == #top_inventory_item_hash then
	stop_rendering_item_hashes = true
	return
end

local newitem = vgui.Create( "DModelPanel" )
top_inventory_item_hash[#top_inventory_item_hash + 1] = newitem
newitem:SetModel( "models/player/kleiner.mdl" )
newitem:SetSize( xsize( 50 ), ysize( 50 ) )
newitem:SetPos( xpos( xposition ), ypos( 30 ) )
newitem.ID = #top_inventory_item_hash

function newitem:LayoutEntity( ent ) return end

end[/lua]