Hi there!
I would like to ask for some help. There is a logic flaw which I cannot figure out…
I’m creating a couple of objects with a factory and I want all of them to be at random but different places.
I’m using a Set to store the vector3 positions and before creating a new object I would like to check if the Set already contains it. I’m using this implementation which should work fine. However the check always returns false. Also debugged it, expected 50 objects were created but at less then 50 positions.
I think the issue is somewhere around the storing local position variable.
Here is the code snippet:
local wallPositionSet = Set.new()
function initMaze()
local counter = NULL
repeat
local position = vmath.vector3(NULL, NULL, ONE)
position.x = math.random(FIRST_INNER_COL, LAST_INNER_COL)
position.y = math.random(FIRST_INNER_ROW, LAST_INNER_ROW)
if not wallPositionSet.contains(wallPositionSet, position) then
factory.create("#maze", position)
wallPositionSet.insert(wallPositionSet, position)
counter = counter + ONE
end
until(counter == FIFTY)
end
Thank you in advance!