EventListener Not Working For Us.

Do I need to add a "local enterFrame = require(“enterFrame”) to use an event listener “enterFrame”)?
I have the following code, it doesn’t look like my enterframe listener is working.

    local function Auto(event)
            print("event.time = "…event.time)
    end
                    
    local function onAutoTouch(event)
        if event.phase ==“ended” then  
            print (“start of enterFrame”)
            Runtime:addEventListener( “enterFrame”, Auto)        
        end    
    end

I can see “start of enterFrame” in my terminal, but the event.time is never displayed.

Your “auto” function is coded as an event, therefore it will not run as a normal Runtime event. If you want it to be a true Runtime event (being called on every frame) remove the (event) portion and just make it it ().

If it’s not an event, how will I check for the elapsed time?

Try something like this:

[lua]
local autoOn = false

local function auto ( event )

  if ( autoOn ) then

    print( “event time”, event.time )

  end

end

local function onAutoTouch( event )

  if ( autoOn ) then

    autoOn = false

  else

    autoOn = true

  end

end

Runtime:addEventListener( “enterFrame”, auto )

–< TEST

onAutoTouch( nil )

[/lua]

Hope that helps.

Cheers.

Your “auto” function is coded as an event, therefore it will not run as a normal Runtime event. If you want it to be a true Runtime event (being called on every frame) remove the (event) portion and just make it it ().

If it’s not an event, how will I check for the elapsed time?

Try something like this:

[lua]
local autoOn = false

local function auto ( event )

  if ( autoOn ) then

    print( “event time”, event.time )

  end

end

local function onAutoTouch( event )

  if ( autoOn ) then

    autoOn = false

  else

    autoOn = true

  end

end

Runtime:addEventListener( “enterFrame”, auto )

–< TEST

onAutoTouch( nil )

[/lua]

Hope that helps.

Cheers.