Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
... plus additional parameters — Gideros Forum

... plus additional parameters

MoKaLuxMoKaLux Member
edited September 2020 in General questions
I have a question please :)
I found how to use ... in a function, my question is can we pass additional params?
For example I have my base class:
LF_Dynamic_Character_Base = Core.class(Sprite)
function LF_Dynamic_Character_Base:init(
		xworld,
		xspritesheet, xname, xcols, xrows,
		xscalex, xscaley,
		xanchorx, xanchory, xoffsetx, xoffsety,
		xdensity, xrestitution, xfriction,
		xBIT, xCOLBIT, xNAME)
Then I can do this:
LF_Dynamic_Player = Core.class(LF_Dynamic_Character_Base)
 
function LF_Dynamic_Player:init(...)
But this doesn't work with additional parameters:
LF_Dynamic_Bat = Core.class(LF_Dynamic_Character_Base)
 
function LF_Dynamic_Bat:init(..., xposx, xposy, xmove)
Thank you for your help.
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

Comments

  • antixantix Member
    edited September 2020
    Yloinks, that is a lot! When you have so many options it is generally better to pass them as a table..
    local options = {
    	xworld = myWorld,
    	xspritesheet = someSpriteSheet,
    	xname = 'abc',
    	xcols = 0,
    	xrows = 0,
    	xscalex = 0,
    	xscaley = 0,
    	xanchorx = 0,
    	xanchory = 0,
    	xoffsetx = 0,
    	xoffsety = 0,
    	xdensity = 0,
    	xrestitution = 0,
    	xfriction = 0,
    	xBIT = 0,
    	xCOLBIT = 0,
    	xNAM = 0,
    }
     
    LF_Dynamic_Character_Base(options)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
  • MoKaLuxMoKaLux Member
    edited September 2020
    hello there antix :)

    I do as you showed but not in this case.

    I build my levels based on Tiled (as you told me before :) )
    -- ***************
    -- PLAYER & OTHERS
    -- ***************
    if objectName == "player" then
    	self.player = LF_Dynamic_Player.new(
    		xworld,
    		"gfx/player/caverman_97x71.png", "player", 6, 7,
    		1, 1,
    		nil, nil, 0, -5,
    		1, nil, nil,
    		G_BITPLAYER, playercollisions, G_PLAYER)
    	self.player.body:setPosition(object.x, object.y)
    	self.mg:addChild(self.player)
    elseif objectName:sub(1,3) == "bat" then
    	local nme01
    	if objectName == "bat01" then
    		nme01 = LF_Dynamic_Bat.new(xworld,
    			"gfx/nmes/sprite-sheet-121x89.png", objectName, 5, 4,
    			1, 1,
    			nil, nil, nil, nil,
    			1, nil, nil,
    			G_BITENEMY, nmecollisions, G_ENEMY01,
    			object.x, object.y, 1) -- *** EXTRA PARAMS TO BAT ***
    	end
    	nme01.body:setPosition(object.x, object.y)
    	nme01:joint(object.x, object.y)
    	self.mg:addChild(nme01)
    	xworld.bats[nme01] = nme01.body
    The bat enemy has some extra params which I'd like to incorporate using (..., extra1, extra2). Is this possible?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • rrraptorrrraptor Member
    edited September 2020 Accepted Answer
    ?
    local Foo = Core.class(Sprite)
     
    function Foo:init(a,b)
    	self.a = a
    	self.b = b
    end
     
    local Bar = Core.class(Foo, function(c,d,...) return ... end) --< "..." must be at the end
     
    function Bar:init(c,d)
    	self.c = c
    	self.d = d
    end
     
    local foo = Foo.new(1,2)
    print(foo.a, foo.b) --< 1, 2
    local bar = Bar.new(3,4, 1,2) --< 1, 2, 3, 4
    print(bar.a, bar.b, bar.c, bar.d)

    Likes: MoKaLux

    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.