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

How to make a function sequence?

Asked by 7 years ago

How would I make a sequence? (For example, whenever the function activates, it'll cycle through each variable, returning to the original.) Is this even possible?

function Colors()
local a =  NumberSequence.new(1, 3) 
            if a == 1 then
            print'one'
            end

            if a == 2 then
            print'two'
            end

            if a == 3 then
            print'three'
            end

end
0
Use a for loop inside a function. RGRage 45 — 7y

1 answer

Log in to vote
-4
Answered by
RGRage 45
7 years ago

Use a for loop:

local NS = {1, 2, 3}

function Colors()
    for i = 1,#NumberSeq do -- Using a for loop goes through each number by one unless changed
        if i == 1 then
            print('one')
        elseif i == 2 then -- elseif goes through that if only for each loop
            print('two')
        elseif i == 3 then
            print('three')
        end
    end
end

event:connect(Colors) -- change the event to the event that should call the function
Ad

Answer this question