Tokio

[HELP] Why not working killTimer?

Recommended Posts

This is the code:

function stimers(thePlayer)
if getElementData(thePlayer,"asdasd") == true then
local lejartimer1 = setTimer(function() 
exports.fly_box:showBox (thePlayer,"info","10 mins!")
local lejartimer2 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","9 mins!")
end,60000, 1)
local lejartimer3 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","8 mins!")
end,120000, 1)
local lejartimer4 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","7 mins!")
end,180000, 1)
local lejartimer5 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","6 mins!")
end,240000, 1)
local lejartimer6 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","5 mins!")
end,300000, 1)
local lejartimer7 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","4 mins!")
end,360000, 1)
local lejartimer8 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","3 mins")
end,420000, 1)
local lejartimer9 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","2 mins")
end,480000, 1)
local lejartimer10 = setTimer(function()
exports.fly_box:showBox (thePlayer,"info","1 mins")
end,540000, 1)
local lejartimer11 = setTimer(function()
setElementVisibleTo(mark, thePlayer, false)
setElementData(thePlayer, "asdasd", false)
local pos = positions[math.random(1,#positions)]
setElementPosition ( mark, pos.x,pos.y,pos.z )
end,600000, 1)
end,100,1)
---
elseif getElementData(thePlayer,"asdasd") == false then
if isTimer ( lejartimer1 ) then killTimer ( lejartimer1 ) end
if isTimer ( lejartimer2 ) then killTimer ( lejartimer2 ) end
if isTimer ( lejartimer3 ) then killTimer ( lejartimer3 ) end
if isTimer ( lejartimer4 ) then killTimer ( lejartimer4 ) end
if isTimer ( lejartimer5 ) then killTimer ( lejartimer5 ) end
if isTimer ( lejartimer6 ) then killTimer ( lejartimer6 ) end
if isTimer ( lejartimer7 ) then killTimer ( lejartimer7 ) end
if isTimer ( lejartimer8 ) then killTimer ( lejartimer8 ) end
if isTimer ( lejartimer9 ) then killTimer ( lejartimer9 ) end
if isTimer ( lejartimer10 ) then killTimer ( lejartimer10 ) end
end
end
addEvent("ctimers",true)
addEventHandler("ctimers", root,stimers)

Why not working the killTimers? How to fix this?

Share this post


Link to post

The timers are defined in different scope and are local, so they aren't available where you want to destroy them. Delete the "local" from where you create timers, to move their declaration above the function. 

Share this post


Link to post
13 minutes ago, quindo said:

The timers are defined in different scope and are local, so they aren't available where you want to destroy them. Delete the "local" from where you create timers, to move their declaration above the function. 

i deleted the local, but still not working the killTimer :S 

Share this post


Link to post
getElementData(thePlayer,"asdasd")

You sure this data is set correctly? i don't see you setting it anywhere in the script

Share this post


Link to post
Just now, quindo said:

getElementData(thePlayer,"asdasd")

You sure this data is set correctly? i don't see you setting it anywhere in the script

This not the full code. :D And yes, correct

Share this post


Link to post

Are you sure that "asdasd" data is false when you try to delete the timers? otherwise it will just create more timers in place of old ones.

  • Thanks 1

Share this post


Link to post
function stimers(thePlayer)
  if getElementData(thePlayer,"asdasd") == false then
    return end
  if getElementData(thePlayer,"asdasd") == true then
  ...

 

Edited by ÆBKV

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.