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

Could a function with parameters help to not repeat this code?

Asked by
FiredDusk 1466 Moderation Voter
7 years ago
Edited 7 years ago

This code is working just fine but I am wondering it there could be a function that has parameter or arguments to make this have less lines.

NOTICE: I'm pretty much repeating the code but some things a different.

while true do
    local canFade = true
    for i = 0,1,.001 do
        cam.CFrame = cam1.CFrame:lerp(cam2.CFrame,i)
        game:GetService('RunService').RenderStepped:wait()
        if i >= .98 and canFade then
            canFade = false
            fade(playerGui:FindFirstChild('Main').FadeBackground)
        end
    end

    local canFade = true
    for i = 0,1,.001 do
        cam.CFrame = cam3.CFrame:lerp(cam4.CFrame,i)
        game:GetService('RunService').RenderStepped:wait()
        if i >= .98 and canFade then
            canFade = false
            fade(playerGui:FindFirstChild('Main').FadeBackground)
        end
    end

    local canFade = true
    for i = 0,1,.001 do
        cam.CFrame = cam5.CFrame:lerp(cam6.CFrame,i)
        game:GetService('RunService').RenderStepped:wait()
        print'c'
        if i >= .98 and canFade then
            canFade = false
            fade(playerGui:FindFirstChild('Main').FadeBackground)
        end
    end

    local canFade = true
    for i = 0,1,.001 do
        cam.CFrame = cam7.CFrame:lerp(cam8.CFrame,i)
        game:GetService('RunService').RenderStepped:wait()
        if i >= .98 and canFade then
            canFade = false
            fade(playerGui:FindFirstChild('Main').FadeBackground)
        end
    end

    local canFade = true
    for i = 0,1,.001 do
        cam.CFrame = cam9.CFrame:lerp(cam10.CFrame,i)
        game:GetService('RunService').RenderStepped:wait()
        if i >= .98 and canFade then
            canFade = false
            fade(playerGui:FindFirstChild('Main').FadeBackground)
        end
    end
end

2
yes... AstrealDev 728 — 7y
0
Ok, I will try then. FiredDusk 1466 — 7y
0
Yes, b/c you wont have to keep rewriting over-and-over. That's one of the powers of lua! >>:D TheeDeathCaster 2368 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

Oh my yes. Make a parameter like cam and just switch out cam10,CFrame to cam so every time you call the function you can just write functionName(cam4.CFrame) or whatever 'cam' you plan to change. Hope I helped! ;)

Ad

Answer this question