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

How do you find a part from a table?

Asked by 10 years ago

I have a 10X10 grid of parts, labeled with letters and numbers, like battleship or chess. What I am trying to do is take a table like this

local middle = {'e5','e6','f5','f6'}
local square = {'d4','d5','d6','d7','e4','e7','f4','f7','g4','g5','g6','g7'}

and then make all the parts that are not in the table disappear. I am not sure how to check if the parts name is in the table. Thank you for reading!

1 answer

Log in to vote
2
Answered by
AxeOfMen 434 Moderation Voter
10 years ago
--tableContains returns true if the string in the partName parameter is in the table
--t: the table to examine
--partName: the string to look for
local function tableContains(t, partName)
    local result = false
    for i,v in ipairs(t) do
        if v == partName then
            result = true
            break
        end
    end
    return result
end

for i,v in ipairs(MyModel:GetChildren()) do
    if not tableContains(middle, v.Name) and not tableContains(square, v.Name) then
        v.Transparency = 1
    end
end
0
Thank you! It seems to work great! User#348 0 — 10y
Ad

Answer this question