This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Henness's profile picture

[Lua][Question] Can't get "and" and "or" to work, I need a little help!

Started by Henness, 24 April 2012 - 01:20 AM
Henness #1
Posted 24 April 2012 - 03:20 AM
How could I get this bit of code to work, I have been fighting it for the past 2 hours. Am I doing the "and" and "or" wrong?

function placetorch() -- Place a torch
if (torches == true) and ((spacingVar or placedValue) == 0) then
  halfdistance = halfdistance - 1
  if (halfdistance or placedValue) == 0 then
   turtle.placeDown()
   if turtle.getItemCount(1) == 0 then
    noTorches = true
   end
   spacingVar = torchspacing + 1
   halfdistance = halfwidth
  
   -- Update Torches Placed
   placedValue = placedValue + 1
   arcwrite(placedValue, 33, 5)
  end
end
end
Luanub #2
Posted 24 April 2012 - 03:26 AM
if and/or syntax is like..


if a == b and c == d then

if a == b or a == c then

if a == b and c == d or b == d then
Henness #3
Posted 24 April 2012 - 03:27 AM
Thanks! I changed it to this, and it worked.

function placetorch() -- Place a torch
if (torches == true) and ((spacingVar == 0) or (placedValue == 0)) then
  halfdistance = halfdistance - 1
  if (halfdistance == 0) or (placedValue == 0) then
   turtle.placeDown()
   if turtle.getItemCount(1) == 0 then
    noTorches = true
   end
   spacingVar = torchspacing + 1
   halfdistance = halfwidth
  
   -- Update Torches Placed
   placedValue = placedValue + 1
   arcwrite(placedValue, 33, 5)
  end
end
end