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

How would I shorten this?

Asked by 9 years ago
print(" Intermission..[10] ") wait(1) print(" Intermission..[9] ") wait(1) print(" Intermission..[8] ") wait(1)
print(" Intermission..[7] ") wait(1) print(" Intermission..[6] ") wait(1) print(" Intermission..[5] ") wait(1)
print(" Intermission..[4] ") wait(1) print(" Intermission..[3] ") wait(1) print(" Intermission..[2] ") wait(1)
print(" Intermission..[1] ") wait(1) print(" Intermission..[0] ") wait(1)

2 answers

Log in to vote
2
Answered by 9 years ago

You can shorten it by using a for-loop and concatinate the loop-index into the string.

There are of course many ways of solving this, but here's an example.

for i = 10, 0, -1 do -- starting at 10, goal is 0, we need to increment by -1
print(" Intermission..["..i.."]") -- i is the index, the changing number in the loop
wait(1)
end
Ad
Log in to vote
1
Answered by 9 years ago

Rather than print that over and over again, I would suggest a loop.

for I=10,1,-1 do  --run the loop 10 times, starting from 10 and counting down to 1
    print( "Intermission..["..tostring(I).."] ") --print stuff
    wait(1) --wait a second
end --end the loop

This answer was provided by Chipio Industries

Answer this question