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

New programmer looking for input on code and suggestions improvement.

Started by MattFightsBears, 27 December 2012 - 11:12 AM
MattFightsBears #1
Posted 27 December 2012 - 12:12 PM
I'm fairly new to programming. I just started messing around with the turtles and looked at a couple lua tutorials then wrote this. I used pretty much 100% of my coding knowledge in this program. So if it's not there, assume I don't know what it is.
The point of this post is I want to learn more of this program and don't know where to go from here. I'm just using this program to show you kind of where I am and show you where I want to end up.

The program checks how wide a tree in front of the turtle is then cuts it down and replants.

I thought about adding functions to get more coal or saplings and putting wood block into a chest as well as a function to bone meal the tree.

I didn't add the refilling functions because I'm not happy with requiring a user to put a chest in a specific location. Untimely I would like to set up a gps array and pathing finding program so I could set waypoints of the appropriate chest so the turtle can go to them where ever they are to refill itself then find it's way back to the tree.
I've seen gps programs on youtube, but I really don't understand how they work.

I will probably add the bonemeal function later on, but I was writing this code in survival and don't have a good bone supply as of now.

Do you guys think it's worth learning and writing it in the gps functions or should I just leave the program simple?
If I do write it in, where should I look to learn how to do that?
MattFightsBears #2
Posted 27 December 2012 - 12:15 PM
I know I forgot to add the code for the program.
It's up now.
Heracles421 #3
Posted 27 December 2012 - 01:55 PM
2 Things:
1) This goes in the ask a pro section, not here
2) The GPS system is quite easy, all you need is to know were your turtle is at and where do you want to go. Example: My turtle is at X: 20, Y: 62, Z: 3 and I want to go to X: 5, Y: 70, Z: -5. How do I do it? Well, you have to do the next math operation: X1-X2 = Blocks to move. The same applies for Y and Z. Now I know I should move -15 blocks on the X axis, 8 on the Y and -8 on the Z. The rest is simply a for loop:

moveX = -15
moveY = 8
moveZ = -8
for i = 0, moveY do
if moveY > 0 then
    turtle.up()
elseif moveY < 0 then
    turtle.down()
end
end
for i = 0, moveX do
if moveX > 0 then
    turtle.forward()
elseif moveX < 0 then
    turtle.backward()
end
end
This is just an example, I don't know if it works, but the program you have to make should be similar to that
MattFightsBears #4
Posted 27 December 2012 - 04:10 PM
2 Things:
1) This goes in the ask a pro section, not here
2) The GPS system is quite easy, all you need is to know were your turtle is at and where do you want to go. Example: My turtle is at X: 20, Y: 62, Z: 3 and I want to go to X: 5, Y: 70, Z: -5. How do I do it? Well, you have to do the next math operation: X1-X2 = Blocks to move. The same applies for Y and Z. Now I know I should move -15 blocks on the X axis, 8 on the Y and -8 on the Z. The rest is simply a for loop:

moveX = -15
moveY = 8
moveZ = -8
for i = 0, moveY do
if moveY > 0 then
	turtle.up()
elseif moveY < 0 then
	turtle.down()
end
end
for i = 0, moveX do
if moveX > 0 then
	turtle.forward()
elseif moveX < 0 then
	turtle.backward()
end
end
This is just an example, I don't know if it works, but the program you have to make should be similar to that

Thank you for the gps program. I'll mess around with it

Okay.
Is there a way I can move this or should I just copy and paste it into a new post?
Heracles421 #5
Posted 27 December 2012 - 04:33 PM
2 Things:
1) This goes in the ask a pro section, not here
2) The GPS system is quite easy, all you need is to know were your turtle is at and where do you want to go. Example: My turtle is at X: 20, Y: 62, Z: 3 and I want to go to X: 5, Y: 70, Z: -5. How do I do it? Well, you have to do the next math operation: X1-X2 = Blocks to move. The same applies for Y and Z. Now I know I should move -15 blocks on the X axis, 8 on the Y and -8 on the Z. The rest is simply a for loop:

moveX = -15
moveY = 8
moveZ = -8
for i = 0, moveY do
if moveY > 0 then
	turtle.up()
elseif moveY < 0 then
	turtle.down()
end
end
for i = 0, moveX do
if moveX > 0 then
	turtle.forward()
elseif moveX < 0 then
	turtle.backward()
end
end
This is just an example, I don't know if it works, but the program you have to make should be similar to that

Thank you for the gps program. I'll mess around with it

Okay.
Is there a way I can move this or should I just copy and paste it into a new post?
Ask an admin