timer.performWithDelay doesn't work properly

local function RemovePlayer() print("Something") end function change(e) if(e.phase=="began")then Player.alpha=1 Player.height=50 Player.width=50 end if(e.phase=="moved")then angle=(math.atan2( (e.y - Player.y), (e.x - Player.x))\*180)/math.pi +90 Player.rotation=angle end if(e.phase=="ended")then transition.to(Player,{time=200,height=32,width=32}) local xx = (e.x-Player.x)\*2 local yy = (e.y-Player.y)\*2 Player.bodyType = "dynamic" Player:applyForce( xx, yy, Player.x, Player.y ) timer.performWithDelay ( 10000,RemovePlayer() ) end return true end

I have the above code, the problem is that timer.performWithDelay doesn’t seem to work correct because the “Something” is printed in the console immediately after the ended phase and not with 10000 delay. Any idea why this happen?

I think it’s just a simple syntax mistake. You don’t need to add the parentheses after RemovePlayer.
Try this: timer.performWithDelay ( 10000, RemovePlayer )

  • I am by no means an expert, so I can’t explain the technical reason why - :stuck_out_tongue:

Whenever I setup a timer and reference a function, I always just put the name of
the function without the parentheses and it works.
Now if you weren’t using a timer and you wanted to go straight to the desired
function, then you would need to use the parentheses - RemovePlayer()

Hope this helps. :smiley:

This is because when you use parenthesis after a function name, it calls the function immediately.  So when you need to call a function using a timer you leave out the parenthesis.

So just:

timer.performWithDelay ( 10000,RemovePlayer)

I think it’s just a simple syntax mistake. You don’t need to add the parentheses after RemovePlayer.
Try this: timer.performWithDelay ( 10000, RemovePlayer )

  • I am by no means an expert, so I can’t explain the technical reason why - :stuck_out_tongue:

Whenever I setup a timer and reference a function, I always just put the name of
the function without the parentheses and it works.
Now if you weren’t using a timer and you wanted to go straight to the desired
function, then you would need to use the parentheses - RemovePlayer()

Hope this helps. :smiley:

This is because when you use parenthesis after a function name, it calls the function immediately.  So when you need to call a function using a timer you leave out the parenthesis.

So just:

timer.performWithDelay ( 10000,RemovePlayer)