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

What is for i = ?

Asked by 9 years ago

I was wondering what for i =1,0,-0.1 do I understand it goes down by .1 but what does the 1,0 mean?

3 answers

Log in to vote
2
Answered by
Irvene 5
9 years ago

1,0 is basically telling the computer it's going to move down from 1 to 0, in transparency, position, etc.

So say we wanted the script to turn transparent when you click on a GUI.

script.Parent.MouseButton1Down:connect(function()
for i = 1,0,-0.1 do -- 1,0 is going to make it go from 1 to 0 in transparency so it's already going to be transparent and it'll go to non transparent. -0.1 is the way you want it to be because it's going backwards basically from 0 to 1. So it's just a common way to set things. If you just made it 0.1, it'd not function correctly because it's a backwards loop. To make it a forwards loop you'd change it from 1,0 to 0,1,0.1 as a positive decimal.
script.Parent.Frame.Transparency = i
wait()

end)

Hope this helped!

0
By the way incase you didn't know this "Wait()" is the amount of time you want the loop to play so if you set it as 1, the script would play it every 1 second. Irvene 5 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

The first digit One tells the script which number to start on and the second digit Zero tells what number the loops in to end at and the third digit -0.1 your loop is going down or up by. If it didn't explain it very well here for i loop

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

Numerical for loops take the form of

for variable = startNumber, endNumber, increment do

The variable will, well, vary. It will change to the correct number each time the loop iterates, starting at startNumber, ending at endNumber, and adding increment to the variable each time.

The best way to understand for loops is to simply start playing with them

for i = 1, 10, 2 do
    print(i)
end

for i = 1, 10 do --The increment by default equals 1
    print(i)
end

for i = 10, 1, -1 do
    print(i)
end

So now that we know a little about for loops, we can start to understand by taking it apart.

for i = 1, 0, -0.1 do

The start number is 1, so the first thing i will ever equal is 1.

The end number is 0, so that is the last thing i will ever equal.

Since the start number is higher than the end number, we must subtract from i's value. If you've been paying attention in math class, you'll know that subtracting a positive is the same as adding a negative. This is what must be done. We will add a negative value to i each time the loop loops, subtracting from its value, so that it will eventually equal 0.

for i = 1, 0, -0.1 do
    print(i)
end

Answer this question