hope you are all doing fine  
 
 I have a problem  
 
 I want to inherit from classes but that doesn't work for me, could you please have a look?I would like to add parameters to a class that inherits another class but that doesn't work for me, could you please have a look?
I have the base class:| Tiled_Shape_Polygon = Core.class(Sprite)
 
function Tiled_Shape_Polygon:init(xworld, xparams, xlevelscale)
	-- params
	local params = xparams or {}
	params.x = xparams.x or 0
	params.y = xparams.y or 0
	...
	self.x = params.x
	self.y = params.y
end | 
| --!NEEDS:../../tiled/tiled_polygon.lua
Collectibles = Core.class(Tiled_Shape_Polygon)
 
function Collectibles:init()
	self.x += 10 -- this works fine
	self.y += 10 -- this works fine
	...
end | 
| function Collectibles:init(xparams2)
	local params2 = xparams2 or {} -- xparams2 will be a table adding extra stuff to collectibles
	...
end | 
| function Tiled_Shape_Polygon:init(xworld, xparams, xlevelscale, xparams2)
	-- params
	local params = xparams or {}
	local params2 = xparams2 or {}
	...
end
 
function Collectibles:init(xworld, xparams, xlevelscale, xparams2)
	local params2 = xparams2 or {} -- xparams2 will be a table adding extra stuff to collectibles
	...
end | 
...
But every time I have this error: attempt to index local 'xparams2' (a nil value)
How can I add extra parameters to 
Collectibles init without adding them to the parent class? Is it possible?
Thank you in advance for your help  
 
                 
Comments
1) check inside particle2D:init which arguments have been passed, so you could determine who is calling constructor and what to do
2) in particle2D leave the init without argumetns and create antoher method like particle2D:create(texRegion, ID) which you could call from blob:init
3) Do not inherit from particle2D but make the instance of it inside blob:init and store as a property so you could use it for anything you wanted to use it
In the first post I believe I tried solution 1) which didn't work for me
So solution 2) looks good enough
Viva Gideros
1024
2048 0.001
512 0.1
Likes: hgy29, MoKaLux