After a few hours of learning quite a lot of scripting, I come across "for loops". The question I want to ask is that why do people do things like:
for i = 0.05, 0.5, 0.05 do
end
Instead of just using normal integers? Thank you in advance.
After a few hours of learning quite a lot of scripting, I come across "for loops". The question I want to ask is that why do people do things like:
for i = 0.05, 0.5, 0.05 do
end
Instead of just using normal integers? Thank you in advance.
It's for incrementally adjusting properties that have a very small range.
For example, take the transparency property. It ranges from 0 to 1, 0 is opaque, 1 is completely invisible.
Let's say you have a weather system or something and you have a cloud that's always there, but invisible when it's not raining, and partially visible when it is raining.
Whenever it starts raining, you probably wouldn't want the cloud to jump from a transparency setting of 1 to 0.5 in an instant, because that would just look unnatural. You'd set up a for loop to create a smooth transition from invisible to partially visible.
for i = 1, 0.5, -.05 do
wait()
cloud.Transparency = i
end
The loop goes from a starting value of 1 to a goal value of 0.5, and incrementally decreases the transparency, and thus producing a smoother transition, as opposed to an instantaneous and unnatural-looking one.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Thank you for the help. I understand now.