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

Turtle.Select not working

Started by agowa338, 07 March 2015 - 10:57 PM
agowa338 #1
Posted 07 March 2015 - 11:57 PM
Ok, I've written a small program, but the following part is not working. The Turtle does not change the selected slot.

if not turtle.getSelectedSlot() == 16 then
   turtle.select(turtle.getSelectedSlot() + 1)
  end

Can someone please explain why this is not working?
Lyqyd #2
Posted 08 March 2015 - 01:04 AM
This doesn't work because "not" has much higher precedence than the comparison operators, so the comparison isn't something like "if not (4 == 16) then", it's actually "if (not 4) == 16 then", and any value that isn't false or nil will become false or nil when you not it. The boolean false value will never be equal to 16, so your code will never enter the if block. You should instead use the inequality operator:


if turtle.getSelectedSlot() ~= 16 then
agowa338 #3
Posted 08 March 2015 - 01:10 AM
Thanks for helping, I haven't noticed, that I missed the brackets.