Evan
Evan

Reputation: 167

Corona "tick" issues - addEventListener

I've been trying to write out a custom tick using the Corona SDK (using Lua). The key seems to be these "eventListeners," but I'm also trying to get them to work with classes. right now i have this class "World" set up. I'm trying to add an EventListener to my "tick" function, but Corona is telling me I can't do it.

function World:tick()
--player:tick()
--camera:tick(player.x,player.y)
--for i=0,monsters.length do
--      monster[i]:tick()
    if(rwalk) then
        mainGroup.x = mainGroup.x-10
    elseif(lwalk) then
        mainGroup.x = mainGroup.x+10
    end
end
Runtime:addEventListener("enterFrame",tick)

Error: Runtime error: assertion failed! stack traceback: [C]: ? [C]: in function 'assert' ?: in function 'getOrCreateTable' ?: in function 'addEventListener' ?: in function 'addEventListener' C:\Users\Evan\Desktop\lua\test game\main.lua:337: in main chunk

Upvotes: 0

Views: 1228

Answers (1)

Mike Lorenz
Mike Lorenz

Reputation: 942

This works for me. Should work for you:

World = {}

function World:tick()
    print "Hello!"
end

display.setStatusBar(display.HiddenStatusBar)
Runtime:addEventListener("enterFrame", World.tick)

All you were missing was to specify the function using World.tick instead of tick.

Upvotes: 3

Related Questions