timer.performWithDelay - Error attempt to index global ' timer' (a number value)

Ok Now i’m lost.

Why do I get this error ?

Platform: iPad / x64 / 6.1 / Intel® HD Graphics 3000 / 3.1.0 - Build 9.17.10.2843
tap
falling
Runtime error
c:\corona projects\test2\main.lua:15: attempt to index global ’
timer’ (a number value)
stack traceback:
        c:\corona projects\test2\main.lua:15: in function <c:\corona projectstest2\main.lua:6>
        ?: in function <?:218>

Code:

display.setStatusBar( display.HiddenStatusBar ) local falling = function() print ("falling callend") end local tap = function(event) if event.phase == "began" then timer = system.getTimer() elseif event.phase == "ended" then local time = system.getTimer() - timer if time \< 100 then print("tap") --move the player else print ("falling") timer.performWithDelay( 1, falling ,1) end end end local object = display.newImage( "ball.png" ) object:addEventListener("touch", tap)

If this is the code verbatim, you haven’t properly commented out the word “timer” next to getTimer()

It should be:

local time = system.getTimer() -- timer

system.getTimer() returns the time where as timer. is an object you are trying to set a object to a number and then trying to call it as a object all at the same time.

change your timer = system.getTimer() to iTime = system.getTimer() and it should get rid of the error.

and what alex said

Good catch, Chris, I didn’t even see that. 

Yea, most be blind :blink:

Thanks

Alex I didn’t see the single dash either lol

If this is the code verbatim, you haven’t properly commented out the word “timer” next to getTimer()

It should be:

local time = system.getTimer() -- timer

system.getTimer() returns the time where as timer. is an object you are trying to set a object to a number and then trying to call it as a object all at the same time.

change your timer = system.getTimer() to iTime = system.getTimer() and it should get rid of the error.

and what alex said

Good catch, Chris, I didn’t even see that. 

Yea, most be blind :blink:

Thanks

Alex I didn’t see the single dash either lol

I have similar problem with my code:

Can post code cause “You are not allowed to use that image extension on this community”

Erroe message: attempt to index global ‘timer’ (a number value)

Have local gameLT variable at the begining of my file, then have local function gameLoop () end and finaly have: elseif ( phase == “did” ) then 

gameLT = timer.performWithDelay (100, gameLoop, 0) 

in my function scene:show

Somewhere in your code you must be reassigning ‘timer’ to be something else. Without seeing it all, it’s difficult to help further.

Thanks, it is. I used some code from internet where was variable with name timer.

I have similar problem with my code:

Can post code cause “You are not allowed to use that image extension on this community”

Erroe message: attempt to index global ‘timer’ (a number value)

Have local gameLT variable at the begining of my file, then have local function gameLoop () end and finaly have: elseif ( phase == “did” ) then 

gameLT = timer.performWithDelay (100, gameLoop, 0) 

in my function scene:show

Somewhere in your code you must be reassigning ‘timer’ to be something else. Without seeing it all, it’s difficult to help further.

Thanks, it is. I used some code from internet where was variable with name timer.