• 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!

Solved Repeat executing function

Tie

New Member
Joined
Jan 7, 2013
Messages
11
Reaction score
3
Location
UK
Hello
I'm making a talkaction and I want to to execute 1 function 10~ times, and I want it to have delay of 2 seconds between each execution
What's the best way to do it?

I tried this but failed:
Lua:
local x = 1
while x < 10 do
   addEvent(doSomething(), 2000)
   x=x+1
end

Thanks
 
Bro Loops isn't used like that i made you a simple script of correct loop​

Lua:
for i=1,10 do
   doPlayerAddItem(cid, 2173, 1)
end

this will happen 10 times. change the number after 1, like​
Lua:
for i=1,3 do
   doPlayerAddItem(cid, 2173, 1)
end
this will happen 3 times and so on​

to make delay between them you should use addEvent like​
Lua:
for i=1,3 do
   addEvent(doPlayerAddItem, 2000, (cid, 2173, 1)) -- this will add to player 1 aol every 2 second for 3 times
end
to use addEvent
First:-Function-
second:-Time---2000 = 2 second
third:-the (cid, blabla)

correct me if i am wrong :D
there is more features of loops like the one you used​
Lua:
local loop = 0
	repeat
		doPlayerAddItem(cid, 2173, 1)
		loop = loop + 1
	until loop >= 10

go to evil hero thread for more information
http://otland.net/f481/scripting-guide-74030/
 
Back
Top