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

Would like help with alternating right/left in turtles on eg. platformbuilding

Started by Neopherus, 20 April 2013 - 04:18 AM
Neopherus #1
Posted 20 April 2013 - 06:18 AM
Hi peeps. Really hope you can help me with this.
Been trying stuff in SSP, googling, general spamtesting etc, but I just cannot find a way for my turtle to know when to turn left and when to turn right. (think platformbuilding, going to x then turning right - going to y then turning left)

I wrote a program to make me an enderman fall-box earlier and that made me think: I want it to know how to make a roof as well!

I'm self taught and as such I only know how to make programs using arguments like for "i = 1,#" or "i = 1,tArgs[x] do"

Now I'm hoping to hit the next level whereas I can teach turtles to "know" when to turn right/left without having to hardcode the program itself. (I love variables/arguments)

Please do let me know if this is not enough information. I really want to learn this last feature before I consider myself done with "the general stuff".
theoriginalbit #2
Posted 20 April 2013 - 06:25 AM
Ok so it depends on how you are doing it, but here is an example


for width = 0, 15 do
  for length = 0, 15 do
    turtle.forward()
  end
  if width % 2 == 0 then
    turtle.turnRight()
  else
    turtle.turnLeft()
  end
end
this will move over a 16x16 area. how it works is the % operator is modulo/modulus, and checks that the number on the left is a multiple of the number on the right.
So
10 % 3 is 1 … 3 goes into 10, 3 times with a remainder of 1
whereas
9 % 3 is 0 … 3 goes into 9, 3 times with a remainder of 0
and
15 % 4 is 3 … 4 goes into 15, 3 times with a remainder of 3

hope this makes sense and helps :)/>
Neopherus #3
Posted 20 April 2013 - 07:11 AM
That makes it alot easier to understand! Thank you :)/> I will definately bookmark this for future referance.

If I could ask one favor though: I use the 1,4 argument for the box itself (length+width combined), - since I want this box squared - and a seperate argument for height.
If you (or someone with the same amount of knowledge) can check my script (http://pastebin.com/bD5A5Qp4) and attempt to implement the modulus in a seperate function to be added when he's done with the walls I would be forever greatful!

I will probably re-write my program tomorrow - using theoriginalbit's awesome explanation -
when my beergoggles are gone, but I'm trying to work fast to get this enderman farm done in spawn on the server I'm on.