Posted 01 July 2014 - 03:22 PM
So, I'm making a map function, and in part of it it has a large amount of comparing, in which I need several or statements… What is the best way of comparing this? Do I need to write out a bunch more elsif statements, or is there an easier way? I don't think I can use multiple or statements, but maybe there is another way.
if l == tbl.y - 1 and line:sub( tbl.x, tbl.x ) == "#" then --#I want to compare the character to #, U, or D. But I really dont want to write out 12 more statements.
--turtle should move forward
return function() orient( "up" ) return turtle.forward() end, {x = tbl.x, y = tbl.y - 1, z = tbl.z}
elseif l == tbl.y and line:sub( tbl.x - 1, tbl.x - 1 ) == "#" then
--turtle should move "left"
return function() orient( "left" ) return turtle.forward() end, {x = tbl.x - 1, y = tbl.y, z = tbl.z}
elseif l == tbl.y and line:sub( tbl.x + 1, tbl.x + 1 ) == "#" then
--turtle should move "right"
return function() orient( "right" ) return turtle.forward() end, {x = tbl.x + 1, y = tbl.y, z = tbl.z}
elseif l == tbl.y + 1 and line:sub( tbl.x, tbl.x ) == "#" then
--turtle should move back
return function() orient( "down" ) return turtle.forward() end, {x = tbl.x, y = tbl.y + 1, z = tbl.z}
elseif oldChar:upper() == "U" then
--turtle should move up
return function() return turtle.up() end, {x = tbl.x, y = tbl.y, z = tbl.z + 1}
elseif oldChar:upper() == "D" then
--turtle should move down
return function() return turtle.down() end, {x = tbl.x, y = tbl.y, z = tbl.z - 1}
end