Jump to content

Waiting for timer to finish before continuing with function.


quindo

Recommended Posts

Posted

Hey, I'm working on some small project of mine, I want to create a function where there is a timer, and some other things. The other things need to start after the timer has finished, how can I do it?

Here is sample of my code, a tried to put destroyElement and table.remove in another timer, but that doesn't work for me either.

setTimer( 
    function() 
        a = math.floor(math.random(#arena)) 
        setTimer( 
            function() 
                trans = trans-25 
                setElementAlpha(arena[a],trans) 
                outputChatBox(a .. " done") 
            end, (GTIME-100)/8,6) 
        destroyElement(arena[a]) 
        table.remove(arena, a) 
        outputChatBox(a .. " deleted", getRootElement(), 255, 0, 0) 
        trans = 255 
end, GTIME, #arena-1) 

Thanks in advance for any help.

Posted
Hey, I'm working on some small project of mine, I want to create a function where there is a timer, and some other things. The other things need to start after the timer has finished, how can I do it?

Here is sample of my code, a tried to put destroyElement and table.remove in another timer, but that doesn't work for me either.

setTimer( 
    function() 
        a = math.floor(math.random(#arena)) 
        setTimer( 
            function() 
                trans = trans-25 
                setElementAlpha(arena[a],trans) 
                outputChatBox(a .. " done") 
            end, (GTIME-100)/8,6) 
        destroyElement(arena[a]) 
        table.remove(arena, a) 
        outputChatBox(a .. " deleted", getRootElement(), 255, 0, 0) 
        trans = 255 
end, GTIME, #arena-1) 

Thanks in advance for any help.

Full code would be useful

Posted
Simply put the code you want to execute once the timer's done inside that timer. Otherwise, you can use getTimerDetailsto see if it's still running, stopped running or does not exist.

I got to say.. first time i see this function... looked for it for a long time...

Posted

Thanks for all help, i managed to find out what was wrong with my script. When I didn't use a timer for 2nd part it was just faster than first timer. When i put 2nd part into timer i set it to wrong time, so a was randomly generated too fast. I just put it with a bit smaller time and it works fine. here's the fixed code, i didn't explain properly at first what i meant, so sorry for that.

setTimer( 
    function() 
        a = math.floor(math.random(#arena)) 
        setTimer( 
            function() 
                trans = trans-25 
                setElementAlpha(arena[a],trans) 
                outputChatBox(a .. " done") 
            end, (GTIME-100)/8,6) 
        setTimer( 
            function() 
                destroyElement(arena[a]) 
                table.remove(arena, a) 
                outputChatBox(a .. " deleted", getRootElement(), 255, 0, 0) 
                trans = 255 
            end, GTIME-50,1) 
end, GTIME, #arena-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...