Jump to content

I cant kill this Timer why?


Eistee

Recommended Posts

Posted
function () 
outputChatBox ("bla bla", source, 255, 0, 0, false) 
killTimer (timer1) 
end 
  
  
  
function (player) 
    timer1 = setTimer ( function() 
        outputChatBox ("miau miau", source, 255, 0, 0, false) 
    end, 5000, 1 ) 
end 

I like to kill the timer "timer1" before it starts.

So, before 5 seconds pass, the timer 1 should be killed.

Error: WARNING: points\core_s.lua:150: Bad argument @ 'killTimer' [Expected lua-timer at argument 1, got nil]

Posted

[lua]

function hi()

outputChatBox ("bla bla", source, 255, 0, 0, false)

if isTimer(timer1) then

killTimer (timer1)

end

end

function (player)

timer1 = setTimer ( function()

outputChatBox ("miau miau", source, 255, 0, 0, false)

end, 5000, 1 )

end

hi()

[lua]

Posted
  
local timer1 
function () 
outputChatBox ("bla bla", source, 255, 0, 0, false) 
if isTimer(timer1) then 
killTimer (timer1) 
end 
end 
  
  
  
function (player) 
    timer1 = setTimer ( function() 
        outputChatBox ("miau miau", source, 255, 0, 0, false) 
    end, 5000, 1 ) 
end 

Posted

You can't kill a timer before it's created, secondly the third argument (1) in the creation of your timer will kill it automatically. If you want to kill it before as some kind of interrupt you need to make a command handler for your first function and give it a name, as it is now the kill function will be executed as soon you start the resource.

Posted

Oh ye thank you :)

How can i fix this? :

        setTimer ( function() 
            if isTimer(timer1) then 
                killTimer ( timer1 ) 
            elseif  isTimer(timer2) then 
                killTimer ( timer2 ) 
            elseif  isTimer(timer3) then 
                killTimer ( timer3 ) 
            elseif  isTimer(timer4) then 
                killTimer ( timer4 )                 
            end, 1000, 1 ) 
        end 

[2014-08-22 12:19:42] SCRIPT ERROR: points\core_s.lua:229: unexpected symbol near ','

[2014-08-22 12:19:42] ERROR: Loading script failed: points\core_s.lua:229: unexpected symbol near ','

Posted

By ending the function you have within your timer of course.

setTimer ( function() 
    if isTimer(timer1) then 
        killTimer ( timer1 ) 
    elseif  isTimer(timer2) then 
        killTimer ( timer2 ) 
    elseif  isTimer(timer3) then 
        killTimer ( timer3 ) 
    elseif  isTimer(timer4) then 
        killTimer ( timer4 )                 
    end 
end, 1000, 1 ) 
  

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.
×
×
  • Create New...