Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
function expected, got nil — Gideros Forum

function expected, got nil

Tstar_oneTstar_one Member
edited May 2013 in Bugs and issues
i have a timer in a class i every time i try this there is the Error : function expected, got nil
i dont know why :(

dave= Core.class(Sprite)
local fall_timer = Timer.new(10,0)


function dave:init()

fall_timer:addEventListener(Event.TIMER, self.onJumpFallTimer )

end

function dave:onJumpFallTimer()

-- Do something...

end

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Hello @Tstar_one it seems the error is somewhere else, if I copy this to empty project, it works:
    dave= Core.class(Sprite)
    local fall_timer = Timer.new(10,0)
     
     
    function dave:init()
     
     fall_timer:addEventListener(Event.TIMER, self.onJumpFallTimer )
     fall_timer:start()
     
    end
     
    function dave:onJumpFallTimer()
     
     -- Do something...
     
     print("me")
     
    end
     
    dave.new()
    on which line does the error show and what is on that line?
  • @Tstar_one
    You must have used self in the dave:onJumpFallTimer function that you have not pass through the fall_timer:addEventListener

    I think just change to fall_timer:addEventListener(Event.TIMER, self.onJumpFallTimer, self ) will works.
  • This Line fall_timer:addEventListener(Event.TIMER , self.onJumpFallTimer)

    cause the error even with self at the end :( and the function is emtpy same thing

    lua:53: bad argument #2 to 'addEventListener' (function expected, got nil)
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    if you are really doing it inside dave:init then you must have reassigned self variable to something else.
    Unfortunately, without seeing more code, we can't really help you
  • I found it !!! the Functions where wirtten in an function i set an end wrong thank you all :)
Sign In or Register to comment.