Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I loop a function X number of times?

Asked by 9 years ago

I want to loop a function, but not infinitely. Let's say I wanted to do it 5 times.

function spawnmob()
end

spawnmob()
spawnmob()
spawnmob() -- not what i want to do
spawnmob()
spawnmob()

Is there a way to loop functions X number of times?

1 answer

Log in to vote
1
Answered by
Async_io 908 Moderation Voter
9 years ago

Use a return statement :)

local o = 0
return
o = o + 1
spawnmob()
wait (1) ---Replace with number of seconds within each spawn (IMPORTANT)
until o = 5 ----Replace 5 with whatever

Best of Luck

0
Thanks. slicer39alt 5 — 9y
0
Actually, have a problem with that. See, I'm using it in a function. The function is fired by a loop that checks for something. It doesn't work in a function. slicer39alt 5 — 9y
0
Fixed it myself using wiki. Still thanks, this led me to the wiki. slicer39alt 5 — 9y
0
@better or use a for loop since that's what for loops are for FutureWebsiteOwner 270 — 9y
Ad

Answer this question