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

Is there a way to make this script smaller?

Asked by
iFlusters 355 Moderation Voter
8 years ago

Just wondering if there was a way in shortening this script, while still keeping the Value's of the Size.

function Countdown()
script.Parent.FontSize = "Size32"
wait()
script.Parent.FontSize = "Size28"
wait()
script.Parent.FontSize = "Size24"
wait()
script.Parent.FontSize = "Size18"
wait()
script.Parent.FontSize = "Size14"
wait()
script.Parent.FontSize = "Size12"
wait()
script.Parent.FontSize = "Size11"
wait()
script.Parent.FontSize = "Size12"
wait()
script.Parent.FontSize = "Size14"
wait()
script.Parent.FontSize = "Size18"
wait()
script.Parent.FontSize = "Size24"
wait()
script.Parent.FontSize = "Size28"
wait()
script.Parent.FontSize = "Size32"
end

2 answers

Log in to vote
2
Answered by
Necrorave 560 Moderation Voter
8 years ago

Create an array with the Sizes as indexes.

Then use a for loop to go through them.

--Create an array with  your changes
local sizes = {"Size32", "Size28", "Size24", "Size18", "Size14", "Size12", "Size11", "Size12", "Size14", "Size18", "Size24", "Size28", "Size32")

--For loop that goes through array
for x = 1, #sizes, 1 do
    wait()
    script.Parent.FontSize = sizes[x] --Assigns the index
end

The for loop will only go through the amount of indexes it has than stop.

#sizes is a cool way to return the length of an array.

Let me know if you have any other questions.

3
You can cut the length of array in half by going forward then back. If you're being extra short you could pull the "Size" part into the loop and out of the array. BlueTaslem 18071 — 8y
1
Even shorter, since FontSize is an Enum (http://wiki.roblox.com/index.php?title=API:Enum/FontSize), you can store its integer value instead (i.e. sizes = {11, 10, 7, 6, 5, 4, 3, 4, 5, 6, 7, 10, 11}) XAXA 1569 — 8y
0
Hmm, I did not know that myself. I have yet to really delve into GUI's. Good to know though, thanks for sharing. Necrorave 560 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
local function countdown()
local sizes = {32,28,24,18,14,12,11}
for i = 1,#sizes do
script.Parent.FontSize = "Size"..sizes[i]
wait()
end
for i = #sizes,1,-1 do
script.Parent.FontSize = "Size"..sizes[i]
wait()
end
end

Answer this question