Summary
I been use the table.remove() to get rid of objects stored in a table. However I just now learned that apparently despite using remove the other objects don’t shift up. The object I deleted is still considered there but as nil.
Is there anyway I could make a table where I can safely delete objects where the other objects will shift correctly?
Visual
{A, B, C, D}
-- Remove B
{A, nil, C, D}
-- What I want:
{A, C, D}
PS: In case I’m mistaken and it actually is supposed to be doing what I am after, then let me know, it’s probably something I’m doing.
It’s an issue on my end.
My Code:
Summary
function level:ExtendRooms(level)
local max = script.Parent.Settings.Rooms.Value
while #level.Rooms ~= max and #level.Doors ~= 0 do --wait()
--RunService.Heartbeat:Wait()
local roomsFound = Components:GetRooms(level.Type):GetChildren()
local roomOptions = {unpack(roomsFound)}
wait(0.1)
local randomDoor = GetRandomDoor(level)
if(randomDoor) then
local CompletedExtension = false
for i,v in pairs(roomOptions) do
print("LOOP ON", #roomOptions)
local overlapping = Utility:CheckOverlap(newRoom.CollisionBox)
if not overlapping then
CompletedExtension = true
table.insert(Utility.CollisionBoxes, newRoom.CollisionBox)
table.insert(level.Rooms, newRoom)
break
else
for j, g in pairs(roomOptions) do
if g == v then
table.remove(roomOptions, j)
print(#roomOptions)
end
end
newRoom:Destroy()
end
end
end
end
end
What I’m doing:
I’m trying to make the dungeon stop re-using already tested rooms that failed collision. What I do is copy over the list of possible rooms, and remove the ones that failed the test.
For some reason, I manage to get nil on a few, so it never manages to go to LOOP ON 2, 1, etc.
For some reason, nil starts appearing for the objects around that point.
FULL LIST BEFORE REMOVAL:
I’m trying to avoid this:
Instead of letting it fail some 20+ times, Im trying to make each new segment only be about 6, because there are 7 rooms.