• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ Best approach for loops with delays inbetween?

Oneda

Aspiring Spriter
Joined
Dec 3, 2013
Messages
159
Solutions
2
Reaction score
104
Location
Brazil
Hey bois, just wondering whats the best approach to make a loop with delays inbetween.

I.E: I want a magic effect to be sent every second untill 10 seconds have been reached.

I kinda tried looking into addEvent and onThink but couldnt really find much useful info around them
 
Solution
addevent will work for what you want to do, but so will coroutines. Addevent itself is pretty easy to understand its parameters are like so

addEvent(callback, delay, ...) the three dots represent as many more parameters as you want to pass, that is usually where people add a function that they have already created, and in that function you can increase count, or check against os.mtime() to decide when to end your loop if you wanted.

Coroutines are a bit harder to understand, im still learning them myself.
addevent will work for what you want to do, but so will coroutines. Addevent itself is pretty easy to understand its parameters are like so

addEvent(callback, delay, ...) the three dots represent as many more parameters as you want to pass, that is usually where people add a function that they have already created, and in that function you can increase count, or check against os.mtime() to decide when to end your loop if you wanted.

Coroutines are a bit harder to understand, im still learning them myself.
 
Solution
addevent will work for what you want to do, but so will coroutines. Addevent itself is pretty easy to understand its parameters are like so

addEvent(callback, delay, ...) the three dots represent as many more parameters as you want to pass, that is usually where people add a function that they have already created, and in that function you can increase count, or check against os.mtime() to decide when to end your loop if you wanted.

Coroutines are a bit harder to understand, im still learning them myself.
You can't really delay a coroutine like that. What you can do though is called "busy wait". I checked how coroutines work in tfs and it appears that they are blocking the tfs anyway? (tfs is hanging)
 
Last edited:
Back
Top