Howdy. I was attempting a grid inventory system and was wondering if anyone could help me clean up the terrible “bad combination check”. Unfortunately I need it to stop the following from happening in the last video. What could I do to make this more efficient?
function autoFind(position,toolType)
local number = tonumber(position)
local combination = {
number-1,
number+1,
number-4,
number+4,
}
for index,combo in combination do
local bad1 = (number == 4 and combo == number+1)
local bad2 = (number == 8 and combo == number+1)
local bad3 = (number == 5 and combo == number-1)
local bad4 = (number == 9 and combo == number-1)
if bad1 or bad2 or bad3 or bad4 then
warn('bad combination')
else
displayArea(
backpackPanel:FindFirstChild(combo),
Color3.new(1, 0.832349, 0.473213)
)
end
end
end
You can now use these in a single check instead of manually writing four different possible bad cases. For the left and right sides of the pattern, if the index is outside rowMin and rowMax, ignore it. For the top and bottom parts its simpler, just ignore it if the row is less than one or greater than the number of rows.