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

I have problems with infinite loops (MORE INFO IN DESCRIPTION) ?

Asked by
igric 29
7 years ago

So, i want X value (9.5 in my case) to drop down to 9 (x = x - 0.01) but when it reaches value of 9, to rise to 9.5 again (x = x + 0.01). That loop should repeat infinite times.

I've tried several thing but none of them worked. I really hope that some of you pro scripters can help :)

0
there is this cool thing called a while loop.. try using it greatneil80 2647 — 7y

1 answer

Log in to vote
2
Answered by
thesit123 509 Moderation Voter
7 years ago

Are you using if statements such as if X >= 9.5 then and if X <= 9 then?

If not you should consider using it to check the value of X. Using what I just said I did something like this:

while wait(0.1) do -- In the wait, put the seconds you want to pause between each loop

    if X <= 9 then -- Check if X is less than or equal to 9

        X = X + 0.01 -- Add 0.01 to X

    elseif X >= 9.5 then -- Check if X is more than or equal to 9.5

        X = X - 0.01 -- Subtract 0.01 to X

    end
end
0
Didn't really help. I get weird numbers in the output. igric 29 — 7y
0
this script should work though greatneil80 2647 — 7y
Ad

Answer this question