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

Detecting a Value that is already in a list?

Asked by 6 years ago
Edited 6 years ago

I have been struggling with preventing duplicate walls.

The function below takes two points and makes a wall between them. It then added that walls position to list01

The for loop in this function is what I've recently added and its failed at getting the desired result.

01local wallOffset --Offset for midpoint Y axis
02local list01 =  {} -- a table for holding each wall that's been placed
03 
04--Function for creating walls
05local function createWall(last, currentPos)
06    --Create a wall and size it between current and last pillar
07    local wall = Instance.new("Part")
08    wall.Name = "Wall"
09    wall.Size = Vector3.new((last-currentPos).Magnitude,9,1)
10    --(X,Y,Z) of the midpoint of the wall
11    local midX = (last.X + currentPos.X)/2
12    local midY = (last.Y + currentPos.Y)/2 - wallOffset
13    local midZ = (last.Z + currentPos.Z)/2
14    local orientation = (last - currentPos).Unit:Cross(Vector3.new(0,1,0))
15    local CFramePos = Vector3.new(midX, midY, midZ)
View all 36 lines...

I can see that I need to change the for loop(or possibly it's the wrong approach), right now if the first value isn't the same it will add the wall POS to the list regardless if the wall does exist in the list at another index. But if I remove the else statement then I'm not sure where to 'table.insert' when it is a new wall.

That's where I'm at and any help is always appreciated.

1
why are you making the wall before you check if the position is ok? User#5423 17 — 6y
0
@Kingdom5 Where should I make this check? GoodCallMrOlsen 70 — 6y
0
When I check the position of a wall about to be created against the list of walls created, wall.Position comes up (0,0,0) unless it's after parenting the new wall to the workspace. Which resulted in the for loop being where it is? I am open to another route as this hasn't worked GoodCallMrOlsen 70 — 6y

Answer this question