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

Help with simple program :(

Started by rabin0l, 24 December 2015 - 03:44 PM
rabin0l #1
Posted 24 December 2015 - 04:44 PM
I am not very good at this, but I wanted to try to make an automated Ender Lily farm for Tekkit Space. I used some project red stuff and the turtle. I wrote a program with an infinite while loop but the turtle just restarts for no reason.
Here's the code

local boolreds = redstone.getInput("left")
while true do
  if boolreds==true then
    turtle.dig()
    sleep(15)
    turtle.place()
    turtle.select(2)
    turtle.place()
  end
end
Thanks in advance.
LBPHacker #2
Posted 24 December 2015 - 05:46 PM
That program checks for the redstone input on the left once and stores the result in boolreds. It never changes boolreds again. If you run the program while the redstone input is off, boolreds will be set to false forever. Since boolreds is false, the if branch is skipped and the loop is repeated. Doing nothing in an infinite loop results in a yield timeout crash.

The program should check for the redstone input in every iteration of the infinite loop instead.

Solution (read it only if you must, see if you can get it working yourself)
while true do
  local boolreds = redstone.getInput("left") -- check for the redstone signal in every iteration
  if boolreds then -- also, == true is redundant. in Lua, everything's true that's not false or nil
    turtle.dig()
    sleep(15)
    turtle.place()
    turtle.select(2)
    turtle.place()
  end
end
Edited on 24 December 2015 - 08:04 PM
rabin0l #3
Posted 24 December 2015 - 11:35 PM
Yes, LBP, thanks, I figured it out like 20 minutes after I uploaded this :)/>.
I do have a problem though. The lily seeds somehow end up in slot number 3 and I don't know why. I guess I'll have to check every slot and place block :/
LBPHacker #4
Posted 25 December 2015 - 12:29 AM
Instead of the first one, you mean?
rabin0l #5
Posted 25 December 2015 - 01:15 AM
First or second, thats why I place and then switch to slot 2 and place again. I may have figured out what does it. I think it depends on which slot is selected when the seed is broken. Here: pastebin
HPWebcamAble #6
Posted 26 December 2015 - 01:50 AM
I think it depends on which slot is selected when the seed is broken

Exactly, items that are picked up by the turtle will go into the selected slot, if there isn't already a partial stack in the turtles inventory