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

Good method for causing two different for loops to fire simultaneously?

Asked by 4 years ago
local function addClickDetectors()
    getCurrentRowIndex(currentRowIndex)
    getCurrentTileIndex(currentTileIndex)
    for i,v in pairs(tileTableTable) do
        if i <= currentRowIndex + 2 and i >= currentRowIndex - 2 then
            for x,z in pairs(v) do
                if x <= currentTileIndex + 2 and x >= currentTileIndex - 2 then
                    getClickDetector(clickDetectorClone)
                    clickDetectorClone.Parent = z
                end
            end
        end
    end

    for i,v in pairs(tileGrid.Rows:GetChildren()) do
        if i <= currentRowIndex + 2 and i >= currentRowIndex - 2 then
            for x,z in pairs(v:GetChildren()) do
                print(z)
                if x <= currentTileIndex + 2 and x >= currentTileIndex - 2 and z.Value.Value == 250 then
                    z.BrickColor = BrickColor.new("Fossil")
                end
            end
        end
    end
end

The first for loop adds click detectors to the tiles in a two tile radius around the player, the second one changes the color of the tiles to give an easy visual indicator for which tiles are clickable. Currently, you can click on the tiles for a second before they actually light up. What might a good method be for causing these two events to happen simultaneously? Also the two for loops are iterating over two different tables, so I can't just combine them into one. Thank

0
Maybe you can use a spawn(function(), it allows the loop to run while the rest of the code is also running, use the spawn function on the first loop Leamir 3138 — 4y
0
This works thank you GuruNin 5 — 4y
0
Can you accept my answer? Just to get the question marked as "answered" Leamir 3138 — 4y

2 answers

Log in to vote
1
Answered by
Leamir 3138 Moderation Voter Community Moderator
4 years ago

Maybe you can use a spawn(function(), it allows the loop to run while the rest of the code is also running, use the spawn function on the first loop

Ad
Log in to vote
0
Answered by 4 years ago
spawn(function() 
    for i = 1, 10 do
        print(i)
    end
end)

for i = 1, 10 do
    print(1, 10)
end

Spawn Function This creates a thread and it runs the code separately on it.

Answer this question