Table.sort not working

Hello, I’ve encountered a problem with table.sort , basically even if the script is correct my plugin still fails sorting.

So, I’m making a triangle terrain plugin, and I need to sort the triangles when moving the nodes to keep their color and material in correct order. I’ve tried sorting size, position but every time I update the triangle they show up in a different order.


Example:
Before


After:

if I continue the blue triangle keeps changing on the four wedge parts


My code:

local function UpdCube(Point1, Point2, Point3, Point4,wedge1,wedge2,wedge3,wedge4,newAngle)
	if wedge1 and wedge2 and wedge3 and wedge4 then
		
		local wedgeTable = {{wedge1,wedge1.Size.Z},{wedge2,wedge2.Size.Z},{wedge3,wedge3.Size.Z},{wedge4,wedge4.Size.Z}}
		
		table.sort(wedgeTable, function(a,b)
			return a[2] > b[2]
		end)
		
		upd3dTriangle(Point1.Position,Point2.Position,Point3.Position,wedgeTable[1][1],wedgeTable[2][1],newAngle)
		upd3dTriangle(Point2.Position,Point3.Position,Point4.Position,wedgeTable[3][1],wedgeTable[4][1],newAngle)
	else
		Say("Something went wrong during editing. If this persists, contact the owner")
	end
end

anyone can help?

I might be misunderstanding your issue but instead of checking the Z size, try check its total magnitude.

local wedgeTable = {wedge1, wedge2, wedge3, wedge4}	
table.sort(wedgeTable, function(a,b)
	return a.Size.Magnitude > b.Size.Magnitude
end)

I also cleaned up the table slightly

I dont know what’s going on with the script:
I’ve put your part into my script, but still it wont work:


Code:

local function UpdCube(Point1, Point2, Point3, Point4,wedge1,wedge2,wedge3,wedge4,newAngle)
	if wedge1 and wedge2 and wedge3 and wedge4 then
		
		local wedgeTable = {wedge1, wedge2, wedge3, wedge4}	
		local oldWedgeTable = wedgeTable
		table.sort(wedgeTable, function(a,b)
			return a.Size.Magnitude > b.Size.Magnitude
		end)
		
		if wedgeTable == oldWedgeTable then
			print("order is the same!!")
		end
		
		upd3dTriangle(Point1.Position,Point2.Position,Point3.Position,wedgeTable[1],wedgeTable[2],newAngle)
		upd3dTriangle(Point2.Position,Point3.Position,Point4.Position,wedgeTable[3],wedgeTable[4],newAngle)
	else
		Say("Something went wrong during editing. If this persists, contact the owner")
	end
end

Output
image


maybe its just the function or its a bug?
(he function still puts wedges in wrong order)

the issue is likely that your sorting method doesn’t provide a stable consistent order when some wedges have equal size z values
try this

local function UpdCube(Point1, Point2, Point3, Point4, wedge1, wedge2, wedge3, wedge4, newAngle)
    if wedge1 and wedge2 and wedge3 and wedge4 then
        local wedgeTable = {
            {wedge1, wedge1.Size.Z, wedge1.Position.X, wedge1.Position.Y, wedge1.Position.Z},
            {wedge2, wedge2.Size.Z, wedge2.Position.X, wedge2.Position.Y, wedge2.Position.Z},
            {wedge3, wedge3.Size.Z, wedge3.Position.X, wedge3.Position.Y, wedge3.Position.Z},
            {wedge4, wedge4.Size.Z, wedge4.Position.X, wedge4.Position.Y, wedge4.Position.Z}
        }
        
        table.sort(wedgeTable, function(a, b)
            if a[2] ~= b[2] then
                return a[2] > b[2]
            elseif a[3] ~= b[3] then
                return a[3] < b[3]
            elseif a[4] ~= b[4] then
                return a[4] < b[4]
            else
                return a[5] < b[5]
            end
        end)
        
        upd3dTriangle(Point1.Position, Point2.Position, Point3.Position, wedgeTable[1][1], wedgeTable[2][1], newAngle)
        upd3dTriangle(Point2.Position, Point3.Position, Point4.Position, wedgeTable[3][1], wedgeTable[4][1], newAngle)
    else
        Say("Something went wrong during editing. If this persists, contact the owner")
    end
end

somehow, it still doesnt work! What should I even do for this? Maybe its an actual roblox bug but I dont think so.

me thinking

ohhh wait… maybe its the points order! I just didnt realize. I’ll try to adjust the nodes order

EDIT: no its not

it still does the thing
robloxapp-20241006-1952242.wmv (1.3 MB)
(idk why it shows as download)

local function DebugPrint(...)
    print("[TriangleTerrain Debug]", ...)
end

local function DebugWedge(wedge)
    return string.format("Wedge(%s, Size=%.2f, Pos=%.2f,%.2f,%.2f)", 
        wedge.Name, wedge.Size.Z, wedge.Position.X, wedge.Position.Y, wedge.Position.Z)
end

local function upd3dTriangle(pos1, pos2, pos3, wedge1, wedge2, newAngle)
    DebugPrint("Updating triangle:")
    DebugPrint("  Positions:", pos1, pos2, pos3)
    DebugPrint("  Wedges before:", DebugWedge(wedge1), DebugWedge(wedge2))
    DebugPrint("  New Angle:", newAngle)
    
    DebugPrint("  Wedges after:", DebugWedge(wedge1), DebugWedge(wedge2))
end

local function UpdCube(Point1, Point2, Point3, Point4, wedge1, wedge2, wedge3, wedge4, newAngle)
    DebugPrint("UpdCube called with:")
    DebugPrint("  Points:", Point1.Position, Point2.Position, Point3.Position, Point4.Position)
    DebugPrint("  Wedges:", DebugWedge(wedge1), DebugWedge(wedge2), DebugWedge(wedge3), DebugWedge(wedge4))
    DebugPrint("  New Angle:", newAngle)

    if wedge1 and wedge2 and wedge3 and wedge4 then
        local wedgeTable = {
            {wedge1, wedge1.Size.Z, wedge1.Position.X, wedge1.Position.Y, wedge1.Position.Z},
            {wedge2, wedge2.Size.Z, wedge2.Position.X, wedge2.Position.Y, wedge2.Position.Z},
            {wedge3, wedge3.Size.Z, wedge3.Position.X, wedge3.Position.Y, wedge3.Position.Z},
            {wedge4, wedge4.Size.Z, wedge4.Position.X, wedge4.Position.Y, wedge4.Position.Z}
        }
        
        DebugPrint("Before sorting:", 
            DebugWedge(wedgeTable[1][1]), 
            DebugWedge(wedgeTable[2][1]), 
            DebugWedge(wedgeTable[3][1]), 
            DebugWedge(wedgeTable[4][1]))
        
        table.sort(wedgeTable, function(a, b)
            if a[2] ~= b[2] then return a[2] > b[2]
            elseif a[3] ~= b[3] then return a[3] < b[3]
            elseif a[4] ~= b[4] then return a[4] < b[4]
            else return a[5] < b[5] end
        end)
        
        DebugPrint("After sorting:", 
            DebugWedge(wedgeTable[1][1]), 
            DebugWedge(wedgeTable[2][1]), 
            DebugWedge(wedgeTable[3][1]), 
            DebugWedge(wedgeTable[4][1]))
        
        upd3dTriangle(Point1.Position, Point2.Position, Point3.Position, wedgeTable[1][1], wedgeTable[2][1], newAngle)
        upd3dTriangle(Point2.Position, Point3.Position, Point4.Position, wedgeTable[3][1], wedgeTable[4][1], newAngle)
    else
        DebugPrint("Error: One or more wedges are nil")
    end
    
    DebugPrint("UpdCube completed")
end 

provide me the print so i can see where the issue belongs to

[TriangleTerrain Debug]   Positions: -408.4280090332031, 313.34033203125, -170.3352508544922 -357.4280090332031, 286.0387268066406, -169.3352508544922 -409.4280090332031, 282.53887939453125, -121.33525085449219  -  Edit - TerrainEditor:344
  20:36:33.614  [TriangleTerrain Debug]   Wedges before: Wedge(17 , 18 , 27 , 28, Size=37.48, Pos=-379.93,285.34,-116.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84)  -  Edit - TerrainEditor:344
  20:36:33.614  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug]   Wedges after: Wedge(17 , 18 , 27 , 28, Size=37.48, Pos=-379.93,285.34,-116.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84)  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug]   Positions: -357.4280090332031, 286.0387268066406, -169.3352508544922 -409.4280090332031, 282.53887939453125, -121.33525085449219 -350.4280090332031, 288.2391662597656, -112.33525085449219  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug]   Wedges before: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=33.37, Pos=-353.93,287.09,-140.84)  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug]   Wedges after: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=33.37, Pos=-353.93,287.09,-140.84)  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344
  20:36:33.615  [TriangleTerrain Debug] UpdCube called with:  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   Points: -350.4280090332031, 288.2391662597656, -112.33525085449219 -306.4280090332031, 300.0387268066406, -118.33525085449219 -348.4280090332031, 312.4394226074219, -60.33525085449219 -297.4280090332031, 317.6387023925781, -59.33525085449219  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   Wedges: Wedge(28 , 29 , 38 , 39, Size=44.49, Pos=-349.43,300.29,-86.34) Wedge(28 , 29 , 38 , 39, Size=44.89, Pos=-301.93,308.84,-88.84) Wedge(28 , 29 , 38 , 39, Size=28.19, Pos=-328.43,294.09,-115.34) Wedge(28 , 29 , 38 , 39, Size=27.79, Pos=-322.93,315.04,-59.84)  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug] Before sorting: Wedge(28 , 29 , 38 , 39, Size=44.49, Pos=-349.43,300.29,-86.34) Wedge(28 , 29 , 38 , 39, Size=44.89, Pos=-301.93,308.84,-88.84) Wedge(28 , 29 , 38 , 39, Size=28.19, Pos=-328.43,294.09,-115.34) Wedge(28 , 29 , 38 , 39, Size=27.79, Pos=-322.93,315.04,-59.84)  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug] After sorting: Wedge(28 , 29 , 38 , 39, Size=44.89, Pos=-301.93,308.84,-88.84) Wedge(28 , 29 , 38 , 39, Size=44.49, Pos=-349.43,300.29,-86.34) Wedge(28 , 29 , 38 , 39, Size=28.19, Pos=-328.43,294.09,-115.34) Wedge(28 , 29 , 38 , 39, Size=27.79, Pos=-322.93,315.04,-59.84)  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   Positions: -350.4280090332031, 288.2391662597656, -112.33525085449219 -306.4280090332031, 300.0387268066406, -118.33525085449219 -348.4280090332031, 312.4394226074219, -60.33525085449219  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   Wedges before: Wedge(28 , 29 , 38 , 39, Size=44.89, Pos=-301.93,308.84,-88.84) Wedge(28 , 29 , 38 , 39, Size=44.49, Pos=-349.43,300.29,-86.34)  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:36:33.616  [TriangleTerrain Debug]   Wedges after: Wedge(28 , 29 , 38 , 39, Size=44.89, Pos=-301.93,308.84,-88.84) Wedge(28 , 29 , 38 , 39, Size=44.49, Pos=-349.43,300.29,-86.34)  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug]   Positions: -306.4280090332031, 300.0387268066406, -118.33525085449219 -348.4280090332031, 312.4394226074219, -60.33525085449219 -297.4280090332031, 317.6387023925781, -59.33525085449219  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug]   Wedges before: Wedge(28 , 29 , 38 , 39, Size=28.19, Pos=-328.43,294.09,-115.34) Wedge(28 , 29 , 38 , 39, Size=27.79, Pos=-322.93,315.04,-59.84)  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug]   Wedges after: Wedge(28 , 29 , 38 , 39, Size=28.19, Pos=-328.43,294.09,-115.34) Wedge(28 , 29 , 38 , 39, Size=27.79, Pos=-322.93,315.04,-59.84)  -  Edit - TerrainEditor:344
  20:36:33.617  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344

it looks a bit messy
(also the “newAngle” is a boolean, because my terrain also has cliffs.)
also huge thanks for your help!

No problem
It seems the wedges are not being modified during the update process
if that doesn’t work please provide me the entire script also provide me the debugging

local function DebugPrint(...)
    print("[TriangleTerrain Debug]", ...)
end

local function DebugWedge(wedge)
    return string.format("Wedge(%s, Size=%.2f, Pos=%.2f,%.2f,%.2f)", 
        wedge.Name, wedge.Size.Z, wedge.Position.X, wedge.Position.Y, wedge.Position.Z)
end

local function upd3dTriangle(pos1, pos2, pos3, wedge1, wedge2, newAngle)
    DebugPrint("Updating triangle:")
    DebugPrint("  Positions:", pos1, pos2, pos3)
    DebugPrint("  Wedges before:", DebugWedge(wedge1), DebugWedge(wedge2))
    DebugPrint("  New Angle:", newAngle)
    
    local center = (pos1 + pos2 + pos3) / 3
    local size = (pos1 - pos2).Magnitude
    
    wedge1.Size = Vector3.new(size, size, size)
    wedge1.CFrame = CFrame.new(center, pos1) * CFrame.Angles(0, math.pi/2, 0)
    
    wedge2.Size = Vector3.new(size, size, size)
    wedge2.CFrame = CFrame.new(center, pos2) * CFrame.Angles(0, -math.pi/2, 0)
    
    if newAngle then
        wedge1.CFrame = wedge1.CFrame * CFrame.Angles(math.pi/4, 0, 0)
        wedge2.CFrame = wedge2.CFrame * CFrame.Angles(-math.pi/4, 0, 0)
    end
    
    DebugPrint("  Wedges after:", DebugWedge(wedge1), DebugWedge(wedge2))
end

local function UpdCube(Point1, Point2, Point3, Point4, wedge1, wedge2, wedge3, wedge4, newAngle)
    DebugPrint("UpdCube called with:")
    DebugPrint("  Points:", Point1.Position, Point2.Position, Point3.Position, Point4.Position)
    DebugPrint("  Wedges:", DebugWedge(wedge1), DebugWedge(wedge2), DebugWedge(wedge3), DebugWedge(wedge4))
    DebugPrint("  New Angle:", newAngle)

    if wedge1 and wedge2 and wedge3 and wedge4 then
        local wedgeTable = {
            {wedge1, wedge1.Size.Z, wedge1.Position.X, wedge1.Position.Y, wedge1.Position.Z},
            {wedge2, wedge2.Size.Z, wedge2.Position.X, wedge2.Position.Y, wedge2.Position.Z},
            {wedge3, wedge3.Size.Z, wedge3.Position.X, wedge3.Position.Y, wedge3.Position.Z},
            {wedge4, wedge4.Size.Z, wedge4.Position.X, wedge4.Position.Y, wedge4.Position.Z}
        }
        
        DebugPrint("Before sorting:", 
            DebugWedge(wedgeTable[1][1]), 
            DebugWedge(wedgeTable[2][1]), 
            DebugWedge(wedgeTable[3][1]), 
            DebugWedge(wedgeTable[4][1]))
        
        table.sort(wedgeTable, function(a, b)
            if a[2] ~= b[2] then return a[2] > b[2]
            elseif a[3] ~= b[3] then return a[3] < b[3]
            elseif a[4] ~= b[4] then return a[4] < b[4]
            else return a[5] < b[5] end
        end)
        
        DebugPrint("After sorting:", 
            DebugWedge(wedgeTable[1][1]), 
            DebugWedge(wedgeTable[2][1]), 
            DebugWedge(wedgeTable[3][1]), 
            DebugWedge(wedgeTable[4][1]))
        
        upd3dTriangle(Point1.Position, Point2.Position, Point3.Position, wedgeTable[1][1], wedgeTable[2][1], newAngle)
        upd3dTriangle(Point2.Position, Point3.Position, Point4.Position, wedgeTable[3][1], wedgeTable[4][1], newAngle)
    else
        DebugPrint("Error: One or more wedges are nil")
    end
    
    DebugPrint("UpdCube completed")
end

this is it (your draw triangle function was completely wrong so I just kept the output of it

 20:57:34.409  [TriangleTerrain Debug] UpdCube called with:  -  Edit - TerrainEditor:344
  20:57:34.409  [TriangleTerrain Debug]   Points: -452.4280090332031, 283.8387756347656, -164.3352508544922 -408.4280090332031, 313.34033203125, -170.3352508544922 -449.4280090332031, 301.339599609375, -111.33525085449219 -409.4280090332031, 282.6388854980469, -121.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.409  [TriangleTerrain Debug]   Wedges: Wedge(16 , 17 , 26 , 27, Size=27.52, Pos=-429.43,291.94,-116.34) Wedge(16 , 17 , 26 , 27, Size=45.33, Pos=-408.93,297.94,-145.84) Wedge(16 , 17 , 26 , 27, Size=38.36, Pos=-450.93,292.59,-137.84) Wedge(16 , 17 , 26 , 27, Size=34.49, Pos=-430.43,298.59,-167.34)  -  Edit - TerrainEditor:344
  20:57:34.409  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.409  [TriangleTerrain Debug] Before sorting: Wedge(16 , 17 , 26 , 27, Size=27.52, Pos=-429.43,291.94,-116.34) Wedge(16 , 17 , 26 , 27, Size=45.33, Pos=-408.93,297.94,-145.84) Wedge(16 , 17 , 26 , 27, Size=38.36, Pos=-450.93,292.59,-137.84) Wedge(16 , 17 , 26 , 27, Size=34.49, Pos=-430.43,298.59,-167.34)  -  Edit - TerrainEditor:344
  20:57:34.409  [TriangleTerrain Debug] After sorting: Wedge(16 , 17 , 26 , 27, Size=45.33, Pos=-408.93,297.94,-145.84) Wedge(16 , 17 , 26 , 27, Size=38.36, Pos=-450.93,292.59,-137.84) Wedge(16 , 17 , 26 , 27, Size=34.49, Pos=-430.43,298.59,-167.34) Wedge(16 , 17 , 26 , 27, Size=27.52, Pos=-429.43,291.94,-116.34)  -  Edit - TerrainEditor:344
  20:57:34.410  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.410  [TriangleTerrain Debug]   Positions: -452.4280090332031, 283.8387756347656, -164.3352508544922 -408.4280090332031, 313.34033203125, -170.3352508544922 -449.4280090332031, 301.339599609375, -111.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.410  [TriangleTerrain Debug]   Wedges before: Wedge(16 , 17 , 26 , 27, Size=45.33, Pos=-408.93,297.94,-145.84) Wedge(16 , 17 , 26 , 27, Size=38.36, Pos=-450.93,292.59,-137.84)  -  Edit - TerrainEditor:344
  20:57:34.410  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug]   Wedges after: Wedge(16 , 17 , 26 , 27, Size=38.36, Pos=-450.93,292.59,-137.84) Wedge(16 , 17 , 26 , 27, Size=34.49, Pos=-430.43,298.59,-167.34)  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug]   Positions: -408.4280090332031, 313.34033203125, -170.3352508544922 -449.4280090332031, 301.339599609375, -111.33525085449219 -409.4280090332031, 282.6388854980469, -121.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug]   Wedges before: Wedge(16 , 17 , 26 , 27, Size=34.49, Pos=-430.43,298.59,-167.34) Wedge(16 , 17 , 26 , 27, Size=27.52, Pos=-429.43,291.94,-116.34)  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug]   Wedges after: Wedge(16 , 17 , 26 , 27, Size=27.53, Pos=-429.43,291.99,-116.34) Wedge(16 , 17 , 26 , 27, Size=45.31, Pos=-408.93,297.99,-145.84)  -  Edit - TerrainEditor:344
  20:57:34.411  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug] UpdCube called with:  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug]   Points: -408.4280090332031, 313.34033203125, -170.3352508544922 -357.4280090332031, 286.0387268066406, -169.3352508544922 -409.4280090332031, 282.6388854980469, -121.33525085449219 -350.4280090332031, 288.4391784667969, -112.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug]   Wedges: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84) Wedge(17 , 18 , 27 , 28, Size=37.49, Pos=-379.93,285.49,-116.84) Wedge(17 , 18 , 27 , 28, Size=33.36, Pos=-353.93,287.24,-140.84)  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug] Before sorting: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84) Wedge(17 , 18 , 27 , 28, Size=37.49, Pos=-379.93,285.49,-116.84) Wedge(17 , 18 , 27 , 28, Size=33.36, Pos=-353.93,287.24,-140.84)  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug] After sorting: Wedge(17 , 18 , 27 , 28, Size=37.49, Pos=-379.93,285.49,-116.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84) Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=33.36, Pos=-353.93,287.24,-140.84)  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug]   Positions: -408.4280090332031, 313.34033203125, -170.3352508544922 -357.4280090332031, 286.0387268066406, -169.3352508544922 -409.4280090332031, 282.6388854980469, -121.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.412  [TriangleTerrain Debug]   Wedges before: Wedge(17 , 18 , 27 , 28, Size=37.49, Pos=-379.93,285.49,-116.84) Wedge(17 , 18 , 27 , 28, Size=35.45, Pos=-408.93,297.94,-145.84)  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   Wedges after: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-408.93,297.99,-145.84) Wedge(17 , 18 , 27 , 28, Size=35.44, Pos=-382.93,299.69,-169.84)  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   Positions: -357.4280090332031, 286.0387268066406, -169.3352508544922 -409.4280090332031, 282.6388854980469, -121.33525085449219 -350.4280090332031, 288.4391784667969, -112.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   Wedges before: Wedge(17 , 18 , 27 , 28, Size=35.40, Pos=-382.93,299.69,-169.84) Wedge(17 , 18 , 27 , 28, Size=33.36, Pos=-353.93,287.24,-140.84)  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug]   Wedges after: Wedge(17 , 18 , 27 , 28, Size=37.48, Pos=-379.93,285.54,-116.84) Wedge(17 , 18 , 27 , 28, Size=33.36, Pos=-353.93,287.24,-140.84)  -  Edit - TerrainEditor:344
  20:57:34.413  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug] UpdCube called with:  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   Points: -409.4280090332031, 282.6388854980469, -121.33525085449219 -350.4280090332031, 288.4391784667969, -112.33525085449219 -404.4280090332031, 278.4387512207031, -66.33525085449219 -348.4280090332031, 312.4394226074219, -60.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   Wedges: Wedge(27 , 28 , 37 , 38, Size=43.11, Pos=-376.43,295.44,-63.34) Wedge(27 , 28 , 37 , 38, Size=32.12, Pos=-406.93,280.49,-93.84) Wedge(27 , 28 , 37 , 38, Size=28.53, Pos=-349.43,300.44,-86.34) Wedge(27 , 28 , 37 , 38, Size=39.52, Pos=-379.93,285.49,-116.84)  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug] Before sorting: Wedge(27 , 28 , 37 , 38, Size=43.11, Pos=-376.43,295.44,-63.34) Wedge(27 , 28 , 37 , 38, Size=32.12, Pos=-406.93,280.49,-93.84) Wedge(27 , 28 , 37 , 38, Size=28.53, Pos=-349.43,300.44,-86.34) Wedge(27 , 28 , 37 , 38, Size=39.52, Pos=-379.93,285.49,-116.84)  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug] After sorting: Wedge(27 , 28 , 37 , 38, Size=43.11, Pos=-376.43,295.44,-63.34) Wedge(27 , 28 , 37 , 38, Size=39.52, Pos=-379.93,285.49,-116.84) Wedge(27 , 28 , 37 , 38, Size=32.12, Pos=-406.93,280.49,-93.84) Wedge(27 , 28 , 37 , 38, Size=28.53, Pos=-349.43,300.44,-86.34)  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   Positions: -409.4280090332031, 282.6388854980469, -121.33525085449219 -350.4280090332031, 288.4391784667969, -112.33525085449219 -404.4280090332031, 278.4387512207031, -66.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   Wedges before: Wedge(27 , 28 , 37 , 38, Size=43.11, Pos=-376.43,295.44,-63.34) Wedge(27 , 28 , 37 , 38, Size=39.52, Pos=-379.93,285.49,-116.84)  -  Edit - TerrainEditor:344
  20:57:34.414  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Wedges after: Wedge(27 , 28 , 37 , 38, Size=32.13, Pos=-406.93,280.54,-93.84) Wedge(27 , 28 , 37 , 38, Size=39.50, Pos=-379.93,285.54,-116.84)  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Positions: -350.4280090332031, 288.4391784667969, -112.33525085449219 -404.4280090332031, 278.4387512207031, -66.33525085449219 -348.4280090332031, 312.4394226074219, -60.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Wedges before: Wedge(27 , 28 , 37 , 38, Size=32.12, Pos=-406.93,280.49,-93.84) Wedge(27 , 28 , 37 , 38, Size=28.53, Pos=-349.43,300.44,-86.34)  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Wedges after: Wedge(27 , 28 , 37 , 38, Size=43.11, Pos=-376.43,295.44,-63.34) Wedge(27 , 28 , 37 , 38, Size=28.53, Pos=-349.43,300.44,-86.34)  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug] UpdCube called with:  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Points: -449.4280090332031, 301.339599609375, -111.33525085449219 -409.4280090332031, 282.6388854980469, -121.33525085449219 -448.4280090332031, 299.2394714355469, -60.33525085449219 -404.4280090332031, 278.4387512207031, -66.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.415  [TriangleTerrain Debug]   Wedges: Wedge(26 , 27 , 36 , 37, Size=40.87, Pos=-448.93,300.29,-85.84) Wedge(26 , 27 , 36 , 37, Size=41.61, Pos=-406.93,280.49,-93.84) Wedge(26 , 27 , 36 , 37, Size=32.70, Pos=-426.43,288.84,-63.34) Wedge(26 , 27 , 36 , 37, Size=33.43, Pos=-429.43,291.94,-116.34)  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug] Before sorting: Wedge(26 , 27 , 36 , 37, Size=40.87, Pos=-448.93,300.29,-85.84) Wedge(26 , 27 , 36 , 37, Size=41.61, Pos=-406.93,280.49,-93.84) Wedge(26 , 27 , 36 , 37, Size=32.70, Pos=-426.43,288.84,-63.34) Wedge(26 , 27 , 36 , 37, Size=33.43, Pos=-429.43,291.94,-116.34)  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug] After sorting: Wedge(26 , 27 , 36 , 37, Size=41.61, Pos=-406.93,280.49,-93.84) Wedge(26 , 27 , 36 , 37, Size=40.87, Pos=-448.93,300.29,-85.84) Wedge(26 , 27 , 36 , 37, Size=33.43, Pos=-429.43,291.94,-116.34) Wedge(26 , 27 , 36 , 37, Size=32.70, Pos=-426.43,288.84,-63.34)  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug]   Positions: -449.4280090332031, 301.339599609375, -111.33525085449219 -409.4280090332031, 282.6388854980469, -121.33525085449219 -448.4280090332031, 299.2394714355469, -60.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug]   Wedges before: Wedge(26 , 27 , 36 , 37, Size=41.61, Pos=-406.93,280.49,-93.84) Wedge(26 , 27 , 36 , 37, Size=40.87, Pos=-448.93,300.29,-85.84)  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.416  [TriangleTerrain Debug]   Wedges after: Wedge(26 , 27 , 36 , 37, Size=40.89, Pos=-448.93,300.29,-85.84) Wedge(26 , 27 , 36 , 37, Size=33.39, Pos=-429.43,291.99,-116.34)  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug] Updating triangle:  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug]   Positions: -409.4280090332031, 282.6388854980469, -121.33525085449219 -448.4280090332031, 299.2394714355469, -60.33525085449219 -404.4280090332031, 278.4387512207031, -66.33525085449219  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug]   Wedges before: Wedge(26 , 27 , 36 , 37, Size=33.43, Pos=-429.43,291.94,-116.34) Wedge(26 , 27 , 36 , 37, Size=32.70, Pos=-426.43,288.84,-63.34)  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug]   New Angle: true  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug]   Wedges after: Wedge(26 , 27 , 36 , 37, Size=32.68, Pos=-426.43,288.84,-63.34) Wedge(26 , 27 , 36 , 37, Size=41.60, Pos=-406.93,280.54,-93.84)  -  Edit - TerrainEditor:344
  20:57:34.417  [TriangleTerrain Debug] UpdCube completed  -  Edit - TerrainEditor:344

You are comparing 2 of the same tables

This does not make a new table, use table.clone()
Also you cant compare tables like that. Instead you need some code like this:

for i,v in table1 do
if table2[i] ~= v then
print("tables are different")
break
end
end

alright, I’ll try this when I will wake up tomorrow, thanks for the help anyway!

I found a solution, pretty easy. Basically I added a new attribute for every wedge, called Index. This number goes from 1 to 4, indicating what wedge was that. So, I only need to re-generate the wedges and done!
Also HUGE thanks to @MythicalRealm_Studio that was so much interested on this.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.