This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
Tried to write a strip-mining Program and the turtle just "dances"
Started by Prrrt, 19 June 2013 - 03:34 PMPosted 19 June 2013 - 05:34 PM
Title: Tried to write a strip-mining Program and the turtle just "dances"
Posted 19 June 2013 - 07:11 PM
Split into new topic.
Did you fuel the turtle?
Did you fuel the turtle?
Posted 19 June 2013 - 10:22 PM
^
It would need fuel to dance, or it would just randomly turn in circles. OP could you show us your code? It would be the only way to help find whats wrong with it.
It would need fuel to dance, or it would just randomly turn in circles. OP could you show us your code? It would be the only way to help find whats wrong with it.
Posted 20 June 2013 - 06:21 AM
hey there thanks to move my post, here comes the question:
i tried to wright now the third strip mine program - sorry for my english btw ;)/> - , the turtle is fueld and no program works…. cant figure why… the program has to ask how many sidegangs there should be and how long these should are, and place a torch on the bottom , one in the middle and one the ends of the side gangs… here comes the source code think it should be good…
function weiter()
while turtle.detect() do
turtle.dig()
sleep(0.5)
end
while turtle.detectUp() do
turtle.digUp()
sleep(0.5)
end
if turtle.detectDown() then
turtle.forward()
else
turtle.select(1)
turtle.placeDown()
turtle.forward()
end
end
function umdrehen()
turtle.turnRight()
turtle.turnRight()
end
print("Put Cobble in the first, torches in the last slot")
print("how many lines should there be?")
Stollen = tonumber(read())
print("How long should lines be?")
Laenge = tonumber(read())
Hauptgang = Stollen*3
Links = Laenge
Recht = Laenge
while Stollen > 0 do
weiter()
Hauptgang = Hauptgang - 1
weiter()
Hauptgang = Hauptgang - 1
weiter()
turtle.select(16)
turtle.placeDown()
Hauptgang = Hauptgang - 1
turtle.turnLeft()
while Links > 0 do
weiter()
Links = Links - 1
end
turtle.select(16)
turtle.placeDown()
Links = Laenge
umdrehen()
while Links > 0 do
turtle.forward()
Links = Links - 1
end
while Rechts > 0 do
weiter()
Rechts = Rechts - 1
end
turtle.select(16)
turtle.placeDown()
Rechts = Laenge
umdrehen()
while Rechts > 0 do
turtle.forward()
Rechts = Rechts - 1
end
turtle.turnRight()
end
thanks alot
*edit*: oh and the problem is: the turtle doesnt move, it only turns around on the same place… looks…. funny…
i tried to wright now the third strip mine program - sorry for my english btw ;)/> - , the turtle is fueld and no program works…. cant figure why… the program has to ask how many sidegangs there should be and how long these should are, and place a torch on the bottom , one in the middle and one the ends of the side gangs… here comes the source code think it should be good…
function weiter()
while turtle.detect() do
turtle.dig()
sleep(0.5)
end
while turtle.detectUp() do
turtle.digUp()
sleep(0.5)
end
if turtle.detectDown() then
turtle.forward()
else
turtle.select(1)
turtle.placeDown()
turtle.forward()
end
end
function umdrehen()
turtle.turnRight()
turtle.turnRight()
end
print("Put Cobble in the first, torches in the last slot")
print("how many lines should there be?")
Stollen = tonumber(read())
print("How long should lines be?")
Laenge = tonumber(read())
Hauptgang = Stollen*3
Links = Laenge
Recht = Laenge
while Stollen > 0 do
weiter()
Hauptgang = Hauptgang - 1
weiter()
Hauptgang = Hauptgang - 1
weiter()
turtle.select(16)
turtle.placeDown()
Hauptgang = Hauptgang - 1
turtle.turnLeft()
while Links > 0 do
weiter()
Links = Links - 1
end
turtle.select(16)
turtle.placeDown()
Links = Laenge
umdrehen()
while Links > 0 do
turtle.forward()
Links = Links - 1
end
while Rechts > 0 do
weiter()
Rechts = Rechts - 1
end
turtle.select(16)
turtle.placeDown()
Rechts = Laenge
umdrehen()
while Rechts > 0 do
turtle.forward()
Rechts = Rechts - 1
end
turtle.turnRight()
end
thanks alot
*edit*: oh and the problem is: the turtle doesnt move, it only turns around on the same place… looks…. funny…
Posted 20 June 2013 - 08:26 AM
There are quite a number of problems in that code (you never change the value of "Stollen" after you first define it, for eg!), but best I can make out the turtle should move. Probably not where you want it to, but somewhere, at least.
If you write a script that only does "turtle.forward()", does that work? What about "turtle.select(16)" followed by "turtle.placeDown()"? This sounds like a server permissions issue of some sort to me.
If you write a script that only does "turtle.forward()", does that work? What about "turtle.select(16)" followed by "turtle.placeDown()"? This sounds like a server permissions issue of some sort to me.
Posted 20 June 2013 - 08:37 AM
ok lol the turtle doesnt move a step
i tryed a program with just
turtle.forward()
turtle.forward()
turtle.forward()
and nothing happend… oO
i run a tekkit lite server on my own pc…. is there something i have to change or should i ask the tekkit lite guys better?
thx ;)/>
i tryed a program with just
turtle.forward()
turtle.forward()
turtle.forward()
and nothing happend… oO
i run a tekkit lite server on my own pc…. is there something i have to change or should i ask the tekkit lite guys better?
thx ;)/>
Posted 20 June 2013 - 08:46 AM
I'm guessing you may want to at least re-install ComputerCraft.
Still, before that it may be worth checking the fuel thing again. Does this print something higher then 0?
Still, before that it may be worth checking the fuel thing again. Does this print something higher then 0?
print(turtle.getFuelLevel())
Posted 20 June 2013 - 08:46 AM
How about fueling the turtle?
Edit: Damn, those ninja's nowadays.
Put a burn-able object in the turtle's selected slot.
Do
turtle.refuel()
Now do
x = turtle.getFuelLevel()
print("" ..x)
That will show how much steps it can move.
Edit: Damn, those ninja's nowadays.
Posted 20 June 2013 - 09:05 AM
ok thanks a lot, now it "lives" ^^ filled it with a stack of coal but ther wasnt any fuel… strange…
now it doesnt do what it should do but it do something….
i've wrote another program, does it look better or same stupid? im a real noob and never wrote programs or something so please forgive me ;)/> heres the oter sourcecode:
*edit*: tried the program and there are 2 problems: first, it doesnt plant torches, second, it digs 3 patches forward, then to the left, then it comes back to the middle and then it freezes….
function weiter()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function umdrehen()
turtle.turnRight()
turtle.turnRight()
end
print("Cobble in den ersten Slot, Fackeln in den Letzten!")
print("Wie viele Stollen soll es geben?")
Stollen = tonumber(read())
print("Wie lang sollen die Stollen sein?")
Laenge = tonumber(read())
Hauptgang = Stollen*3
Links = Laenge
Rechts = Laenge
while Hauptgang > 0 do
weiter()
Hauptgang = Hauptgang - 1
weiter()
Hauptgang = Hauptgang - 1
weiter()
turtle.select(16)
turtle.placeDown()
turtle.turnLeft()
while Links > 0 do
weiter()
Links = Links - 1
end
turtle.select(16)
turtle.placeDown()
umdrehen()
Links = Laenge
while Links > 0 do
turtle.forward()
end
while Rechts > 0 do
weiter()
Rechts = Rechts - 1
end
turtle.select(16)
turtle.placeDown()
umdrehen()
Rechts = Laenge
while Rechts > 0 do
turtle.forward()
end
turtle.turnRight()
Hauptgang = Hauptgang - 1
end
now it doesnt do what it should do but it do something….
i've wrote another program, does it look better or same stupid? im a real noob and never wrote programs or something so please forgive me ;)/> heres the oter sourcecode:
*edit*: tried the program and there are 2 problems: first, it doesnt plant torches, second, it digs 3 patches forward, then to the left, then it comes back to the middle and then it freezes….
function weiter()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function umdrehen()
turtle.turnRight()
turtle.turnRight()
end
print("Cobble in den ersten Slot, Fackeln in den Letzten!")
print("Wie viele Stollen soll es geben?")
Stollen = tonumber(read())
print("Wie lang sollen die Stollen sein?")
Laenge = tonumber(read())
Hauptgang = Stollen*3
Links = Laenge
Rechts = Laenge
while Hauptgang > 0 do
weiter()
Hauptgang = Hauptgang - 1
weiter()
Hauptgang = Hauptgang - 1
weiter()
turtle.select(16)
turtle.placeDown()
turtle.turnLeft()
while Links > 0 do
weiter()
Links = Links - 1
end
turtle.select(16)
turtle.placeDown()
umdrehen()
Links = Laenge
while Links > 0 do
turtle.forward()
end
while Rechts > 0 do
weiter()
Rechts = Rechts - 1
end
turtle.select(16)
turtle.placeDown()
umdrehen()
Rechts = Laenge
while Rechts > 0 do
turtle.forward()
end
turtle.turnRight()
Hauptgang = Hauptgang - 1
end
Posted 20 June 2013 - 09:22 AM
At a glance, certain variables aren't being updated in at least a few places where they should be. Some of your "while" loops will never end.
Though, you can do things with "for" loops somewhat more easily then with "while". Eg, this:
… can be re-written as this:
You may want to try this example program to see how "for" loops work:
Though, you can do things with "for" loops somewhat more easily then with "while". Eg, this:
Rechts = Laenge
while Rechts > 0 do
turtle.forward()
Rechts = Rechts - 1 -- (You don't have this line, but probably meant to.)
end
… can be re-written as this:
for i=1,Rechts do -- This loop doesn't NEED to change Rechts at all!
turtle.forward()
end
You may want to try this example program to see how "for" loops work:
for i=1,10 do
print(i)
end
Posted 20 June 2013 - 10:10 AM
ok i understandet that and changed some things….. just want my first program running, im so sorry im such a noob ^^
so here is the updatet code, it works fine, places the torch, moves left, places the next torch, but when it walks back it doesnt use the turtle.forward() but i think my function, and when its back in the middle then it walks to the left and from the left forward…. hard to understand sry…
for example it should dig 2 sidegangs with a length of 3, it digs forward 3 time, plants the torch behind it, digs to the left for the 3 blocks, turns around and plant the torch, BUT then it doesnt only move back to dig the right tunnel but it DIGS back to the middle, turns around again, moves back to the left side it diged, turns to the right and digs forward….. it confuses me a little…. so here comes the code, now with english variables for better understanding ;)/> :
function Move()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function Back()
turtle.turnRight()
turtle.turnRight()
end
print("Cobble in den ersten Slot, Fackeln in den Letzten!")
print("Wie viele Stollen soll es geben?")
Side = tonumber(read())
print("Wie lang sollen die Stollen sein?")
Length = tonumber(read())
Main = Side*3
while Main > 0 do
Move()
Main = Main - 1
Move()
Main = Main - 1
Move()
Back()
turtle.select(16)
turtle.place()
Back()
turtle.turnLeft()
for i=1,Length do
Move()
end
Back()
turtle.select(16)
turtle.place()
for i=1,Length do
turtle.forward()
end
for i=1,Length do
Move()
end
Back()
turtle.select(16)
turtle.placeDown()
for i=1,Length do
turtle.forward()
end
turtle.turnRight()
Main = Main - 1
end
so here is the updatet code, it works fine, places the torch, moves left, places the next torch, but when it walks back it doesnt use the turtle.forward() but i think my function, and when its back in the middle then it walks to the left and from the left forward…. hard to understand sry…
for example it should dig 2 sidegangs with a length of 3, it digs forward 3 time, plants the torch behind it, digs to the left for the 3 blocks, turns around and plant the torch, BUT then it doesnt only move back to dig the right tunnel but it DIGS back to the middle, turns around again, moves back to the left side it diged, turns to the right and digs forward….. it confuses me a little…. so here comes the code, now with english variables for better understanding ;)/> :
function Move()
turtle.dig()
turtle.forward()
turtle.digUp()
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function Back()
turtle.turnRight()
turtle.turnRight()
end
print("Cobble in den ersten Slot, Fackeln in den Letzten!")
print("Wie viele Stollen soll es geben?")
Side = tonumber(read())
print("Wie lang sollen die Stollen sein?")
Length = tonumber(read())
Main = Side*3
while Main > 0 do
Move()
Main = Main - 1
Move()
Main = Main - 1
Move()
Back()
turtle.select(16)
turtle.place()
Back()
turtle.turnLeft()
for i=1,Length do
Move()
end
Back()
turtle.select(16)
turtle.place()
for i=1,Length do
turtle.forward()
end
for i=1,Length do
Move()
end
Back()
turtle.select(16)
turtle.placeDown()
for i=1,Length do
turtle.forward()
end
turtle.turnRight()
Main = Main - 1
end
Posted 20 June 2013 - 10:40 AM
The turtle can't move through the torch.
I've made a few changes to your code, which fixes that (by having the turtle fly over the torches it places), avoids an issue with falling sand/gravel that might've confused it, and generally tidies things up - I haven't tested it, but hopefully this will work, or at least make it a little clearer.
Edit: I've now changed it a little so that if anything ELSE blocks the turtle (eg a mob), it shouldn't get confused.
I've made a few changes to your code, which fixes that (by having the turtle fly over the torches it places), avoids an issue with falling sand/gravel that might've confused it, and generally tidies things up - I haven't tested it, but hopefully this will work, or at least make it a little clearer.
Spoiler
function digForward()
while not turtle.forward() do
turtle.dig()
sleep(0.8) -- Wait for possible falling gravel
end
while turtle.detectUp() do
turtle.digUp()
sleep(0.8) -- Wait for possible falling gravel
end
turtle.digDown()
turtle.select(1)
turtle.placeDown()
end
function turnAround()
turtle.turnRight()
turtle.turnRight()
end
function moveForward()
while not turtle.foward() do end
end
print("Cobble in den ersten Slot, Fackeln in den Letzten!")
print("Wie viele Stollen soll es geben?")
Side = tonumber(read())
print("Wie lang sollen die Stollen sein?")
do Length = tonumber(read())
Main = Side * 3
while Main > 0 do
for i=1,3 do digForward() end
turnAround()
turtle.select(16)
turtle.place()
turnAround()
turtle.turnLeft()
for i=1,Length do digForward() end
turnAround()
turtle.select(16)
turtle.place()
turtle.up()
for i=1,Length do moveForward() end
turtle.down()
for i=1,Length do digForward() end
turnAround()
turtle.select(16)
turtle.place()
turtle.up()
for i=1,Length do moveForward() end
turtle.down()
turtle.turnRight()
Main = Main - 3
end
Edit: I've now changed it a little so that if anything ELSE blocks the turtle (eg a mob), it shouldn't get confused.
Posted 20 June 2013 - 11:14 AM
Sir, your awesome, thank you so much! it works fine, and you code was - except the do befor the variable - excellent
thanks a lot!!
thanks a lot!!