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

How to make a round script?

Asked by 10 years ago

I was wondering how to make a round script that NEVER Ends, so The game can continue.

2 answers

Log in to vote
3
Answered by 10 years ago

There are a few ways to do this. The first method is using a while loop.

while true do
    PlayRound()
end

This will constantly execute any code in the PlayRound function (which will need to be defined above the while loop), and for your case, the code to play your game in rounds will go inside. Another method is an infinite for loop:

for i = 1, math.huge do
    PlayRound()
end

Another would be the repeat-until loop:

repeat
    PlayRound()
until false

One other option you have is a recursive call to your round function.

function PlayRound()
    -- code in here to play the round

    PlayRound() -- start the next round
end

PlayRound() -- start the first round

You'll notice above that the PlayRound function actually calls itself. This will happen infinitely unless (like all other methods) there is an error in your script.

Which method you pick is up to you. The while loop is the easiest to understand, while the recursive function (the last example) would be highly beneficial to learn. It's your call, though.

0
Thanks! stanford7787 0 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago
while true do
    PlayRound()
end

Answer this question