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

How can I change i in a for loop back to it's original value?

Asked by
MemezyDev 172
4 years ago

I probably made no sense in the title, so I'll try to make it more clearer here. I have a fade script that fades text in and out,

1for i = 1, 0, -0.1 do
2    wait()
3    brought.TextTransparency = i
4end

I was wondering if I can redo the for but instead of it going to 0 I want it to go to 1. Is there any way to do this in the same for loop or do I have to make multiple?

0
i think u can't Nguyenlegiahung 1091 — 4y
0
You probably just have to make another loop going from 0-1 DarkDanny04 407 — 4y

3 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

It’s the same in terms of runtime if you had two for loops though...

So I don’t see why you would need to.

Also you can manipulate how much you want i to increase by if you don’t include the increment. So you could just say i + .1 in the for loop or i -.1.

Or you could do it recursively which is the fun way

01local function ForLoop ( i, ending, incrementer, numberOfTimesItRanBackAndForth)
02      if i == 1 then
03         incrementer = -.1
04         if numberOfTimesItRanBackAndForth > 0 then
05             numberOfTimesItRanBackAndForth =  numberOfTimesItRanBackAndForth + 1
06         end
07      elseif i == 0 then
08         Incrementer = .1
09         numberOfTimesItRanBackAndForth =  numberOfTimesItRanBackAndForth + 1
10      end
11      if numberOfTimesBackAndForth == 2 then
12          return
13      end
14 
15       wait()
View all 22 lines...

Look over it and you can understand what it does. You can also set the number of times you want it to go to 0 to 1 and 1 to 0. So if numberOfTimesBackAndForth == 4 it would have went from 1 to 0, 0 to 1, 1 to 0 and 0 to 1.

You can do the same thing I did here in a while loop but without returning. You just have to add if statments and break when it hits a certain amount of loops you want.

Ad
Log in to vote
0
Answered by 4 years ago

You can make another for loop and put your loop for it to repeat, this is my only way that i can think.... For example:

1for i = 1,2 do
2    for i = 1, 0, -0.1 do
3            wait()
4            brought.TextTransparency = i
5    end
6end

Pretty simple

Hope that helped !

Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
4 years ago

I think this is what you're trying to do:

1for i = 1, 0, -0.1 do
2    wait()
3    brought.TextTransparency = i
4end
5for i = 0, 1, 0.1 do
6    wait()
7    brought.TextTransparency = i
8end

Answer this question