It looks like you're new here. If you want to get involved, click one of these buttons!
local categories = { __categoryIndex = 1 } local function getCategory(...) local value = 0 for i, name in ipairs(arg) do if not categories[name] then local v = categories.__categoryIndex * 2 categories.__categoryIndex = v categories[name] = v value = value + v else value = value + categories[name] end end return value end -- Use -- local categoryBits = getCategory("car") -- New category local maskBits = getCategory("car") -- Will only collide with cars print(categoryBits, maskBits) --> 2, 2 local categoryBits = getCategory("plane") -- New category local maskBits = getCategory("plane") -- Will only collide with planes print(categoryBits, maskBits) --> 4, 4 local categoryBits = getCategory("plane") -- Use existing category local maskBits = getCategory("plane", "car") -- Collide with both cars and planes print(categoryBits, maskBits) --> 4, 6 local categoryBits = getCategory("car") -- Use existing category local maskBits = getCategory("plane", "car", "boat") -- Collide with cars, planes, and boats (will create new 'boat' category) print(categoryBits, maskBits) --> 2, 14 |
Likes: ar2rsawseen, MoKaLux