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

My first program

Started by valithor, 11 May 2013 - 10:26 AM
valithor #1
Posted 11 May 2013 - 12:26 PM
Ok so after watching many videos over programming turtles i decided to attempt to make one. It all works other than the part where i want the turtle to place a torch every 10 blocks.


function layer1()
   turtle.dig()
   turtle.forward()
   turtle.turnRight()
   turtle.dig()
   turtle.turnLeft()
   turtle.turnLeft()
   turtle.dig()
   turtle.turnRight()
   turtle.digUp()
   turtle.up()
   turtle.turnRight()
   turtle.dig()
   turtle.turnLeft()
   turtle.turnLeft()
   turtle.dig()
   turtle.turnRight()
   turtle.down()
end

function layer2()
   turtle.digDown()
   turtle.down()
   turtle.turnRight()
   turtle.dig()
   turtle.turnLeft()
   turtle.turnLeft()
   turtle.dig()
   turtle.turnRight()
end


function finish()
  layer1()
  layer2()
  layer2()
  turtle.up()
end


local times = 0
term.write("enter number of stairs")
times = read()
for i = 0, times do
  finish()
end

this is what i have so far i know there is probably a much easier way to do most of this, but right now i am just trying to find out how to get the turtle to place the torch.
I have already tried
if i==5 then
   turtle.placeUp()
end

and that only placed a torch the first time the turtle went 5 blocks but none after that
Edited by
Lyqyd #2
Posted 11 May 2013 - 04:35 PM
Split into new topic.
Engineer #3
Posted 11 May 2013 - 05:03 PM
You can check when the number is divideable by number x. In your case that would be 10, because you want it to place it every 10 blocks, right?

For that who use this: %, the modulus. A short example how this works:

1 % 5 == 1
5 % 5 == 0
7 % 5 == 2
25 % 5 == 0

So if 5 fits in the number for the modulus, then it substracts 5. This is happening until it doesnt fit in the number anymore.
In your program you want to have something like this:

if i % 10 == 0 then
    -- 10 blocks has passed
end