I’m writing a simple maze generation algorithm, but I’m running into a problem in this section of code.
The if statement says that if target == “Front” and copy.Name is not end, then the if statement should run, printing copy.Name along with a bunch of other stuff.
However, if we look at the output when ran, we can see copy.Name printed as “End” even though the if statement requires copy.Name not to be end to run, along with an error caused by this. I’m not sure what could’ve caused this to occur, so any help with this would be appreciated.
Snippet of code + output window
if target == "Front" and copy.Name ~= "End" then
generatePart(copy.Connectors.Front.Position, length + 1, false, rotation)
print(copy.Name)
--copy.Connectors.Front.Depth = copy.Connectors.Front.Depth + 1
copy.Connectors.Front.Occupied = true
end
We need more of your code because everything looks fine. However, I do see some things that could be improved that might fix your code. Here are some updates I made, although there are probably more.
if string.lower(target) ~= "front" or string.lower(copy.Name) == "end" or not copy.Connectors[target] then return end
generatePart(copy.Connectors[target].Position, length + 1, false, rotation)
print(copy.Name)
--copy.Connectors.Front.Depth = copy.Connectors.Front.Depth + 1
copy.Connectors[target].Occupied = true