How do i add a table to this function?

ive searched but cant find so here i am…

i know i can add a table like this to this function

 local function tb1:removeScene() print("test") end

but i cant add one to this function…

 local onCollision = function(self, event) if event.phase == "began" then local hit = self.value local other = event.other.value if other == 1 then --test end return true end end

** UPDATE FIXED TYPO **

I’m a little unclear on what you’re trying to do, but I think this is what you want:

local obj = display.newCircle( 10, 10, 10 ) obj.collision = function( self, event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end obj:addEventListenter( "collision" ) 

which is the same as this:

local obj = display.newCircle( 10, 10, 10 ) function obj:collision( event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end obj:addEventListenter( "collision" )

This is also the same.

local function onCollision( self, event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end local obj = display.newCircle( 10, 10, 10 ) obj.collision = onCollision-- field must be named collision obj:addEventListenter( "collision" )

** UPDATE FIXED TYPO ON doit2() **

By the way, the question is backwards.

You attach a function to a table, not vice versa.

Also function attached to tables are called methods.

\_G.myVar = 10 -- Global local myVar2 = 10 -- Local local aTbl = {} -- Table aTbl.name = "Bob" -- A field on the table. (also an entry in table, indexed by string "name" -- same as aTbl["name"] = "Bob" local function doit() -- A local function end function aTbl:doit1() -- A method with implied self ':' (colon) notation print( self.name ) end aTbl.doit2 = function( self ) -- A method with explicit self '.' (dot) notation print( self.name ) end aTbl:doit1() -- prints "Bob" aTbl:doit2() -- prints "Bob" aTbl.doit1( aTbl ) -- prints "Bob" aTbl.doit2( aTbl ) -- prints "Bob" local aTbl2 = {} -- Another table aTbl2.name = "Sue" -- A field on the table. aTbl:doit1( aTbl2 ) -- prints "Bob" aTbl:doit2( aTbl2 ) -- prints "Bob" aTbl.doit1( aTbl2 ) -- prints "Sue" aTbl.doit2( aTbl2 ) -- prints "Sue"

** UPDATE FIXED TYPO **

I’m a little unclear on what you’re trying to do, but I think this is what you want:

local obj = display.newCircle( 10, 10, 10 ) obj.collision = function( self, event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end obj:addEventListenter( "collision" ) 

which is the same as this:

local obj = display.newCircle( 10, 10, 10 ) function obj:collision( event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end obj:addEventListenter( "collision" )

This is also the same.

local function onCollision( self, event ) -- field must be named collision if event.phase == "began" then -- fill in your own guts the following is just my example. display.remove(self) end return true end local obj = display.newCircle( 10, 10, 10 ) obj.collision = onCollision-- field must be named collision obj:addEventListenter( "collision" )

** UPDATE FIXED TYPO ON doit2() **

By the way, the question is backwards.

You attach a function to a table, not vice versa.

Also function attached to tables are called methods.

\_G.myVar = 10 -- Global local myVar2 = 10 -- Local local aTbl = {} -- Table aTbl.name = "Bob" -- A field on the table. (also an entry in table, indexed by string "name" -- same as aTbl["name"] = "Bob" local function doit() -- A local function end function aTbl:doit1() -- A method with implied self ':' (colon) notation print( self.name ) end aTbl.doit2 = function( self ) -- A method with explicit self '.' (dot) notation print( self.name ) end aTbl:doit1() -- prints "Bob" aTbl:doit2() -- prints "Bob" aTbl.doit1( aTbl ) -- prints "Bob" aTbl.doit2( aTbl ) -- prints "Bob" local aTbl2 = {} -- Another table aTbl2.name = "Sue" -- A field on the table. aTbl:doit1( aTbl2 ) -- prints "Bob" aTbl:doit2( aTbl2 ) -- prints "Bob" aTbl.doit1( aTbl2 ) -- prints "Sue" aTbl.doit2( aTbl2 ) -- prints "Sue"