function f1() end
function f2() end
local t = {
[1] = { col = createColSphere( ... ), funct = f1 };
[2] = { col = createColSphere( ... ), funct = f2 };
}
function foo()
-- ...
addEventHandler( 'onColShapeHit', t[1].col, t[1].funct )
-- ...
end
Или так...
CColShape = {}
CColShape.__index = CColShape
function CColShape:new( fX, fY, fZ, fR, fFunction )
local o = { col = createColSphere( fX, fY, fZ, fR ), funct = fFunction }
return setmetatable( o, self )
end
function CColShape:setActive( state )
if state then
addEventHandler( 'onColShapeHit', self.col, self.funct )
else
removeEventHandler( 'onColShapeHit', self.col, self.funct )
end
end
function CColShape:destroy( )
destroyElement( self.col )
self = nil
end
function f1() end
function f2() end
local cols = {
city = CColShape:new( 100, 20, 50, 10, f1 )
bank = CColShape:new( 50, 45, 80, 5, f2 )
}
function foo()
-- ...
cols.bank:setActive( true )
-- ..
end