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

Why can I add, but not subtract?

Asked by
Maxomega3 106
10 years ago

So I'm working with a point light, and I'm trying to get a glowing effect that gradually changes from one color to another.

light = script.Parent;
r =0-- math.random (0,255)
g = 0--math.random (0,255)
b = 255--math.random (0,255)
colors = {r,g,b}

function UpdateColor ()
    light.Color = Color3.new (r/255,g/255,b/255)
    wait (.1)
end

while wait () do
    print 'stage 1'
        for i = 0,50-r do
            if r < 255 then
                r = r + 5;
                UpdateColor () -- fades to purple, this is where the color is 255,0,255
            else r = 0;
                UpdateColor ()
            end
        end
    print 'stage 2'
        for i = 0,50-b do -- 50 is one less than 255/5.
            if b > 0 then
                b = b - 5; -- this is why I divide it by 5
                UpdateColor () -- fades to red, this doesn't work! Right now the color is still 255,0,255
            else b = 255;
                UpdateColor ()
            end
        end

Any and all help will be appreciated.

2 answers

Log in to vote
0
Answered by
Destrings 406 Moderation Voter
10 years ago

You can, the problem is that the statement is not being executed because of

for i = 0,50-b do 

Since b = 255, 50 - 255 is -205, so for 0,-205 is not going to execute because the default step is 1

0
Thanks. It's fixed! I'm really prone to making dumb mistakes like that, haha! Maxomega3 106 — 10y
Ad
Log in to vote
5
Answered by 10 years ago

It is going to -205 because the variable b = 255...........

0
So when you do for = 1,50-b it goes to -205 fireboltofdeath 635 — 10y

Answer this question