51 posts
Posted 08 October 2012 - 04:11 PM
Can some one please Tell my Why this wont work, i have a feeling its missing something
function checkFuel()
if turtle.getFuelLevel() <= z*2+2 then
turtle.select(16)
turtle.refuel(1)
end
Function moveback()
turtle.moveBack (8)
turtle.digDown ()
turtle.dig ()
turtle.moveForward ()
turtle.moveDown ()
Tunnel (10)
loop
Anyone help?
many thanks
protexxi
767 posts
Posted 08 October 2012 - 04:18 PM
Hey!
can u please input the Error Code, so we can try to fix your problem?
not that you forgot an "end" at the end of the last function…
and turtle.moveBack() isnt a function…
turtle.back()
436 posts
Posted 08 October 2012 - 04:21 PM
It's not moveBack and moveForward, just back and forward. Same for moveDown.
Also, your checkFuel might not give you enough fuel. Unless you plan to run it every move action, I would extend it.
function checkFuel()
iFuelNow = turtle.getFuelLevel()
if iFuelNow <= z*2+2 then
turtle.select(16)
turtle.refuel(1)
iFuelNew = turtle.getFuelLevel()
if iFuelNew <= z*2+2 then
iFQuantum = iFuelNew - iFuelNow
iNeed = math.ceil((z*2+2 - iFuelNew)/iFQuantum)
turtle.refuel(iNeed)
end
end
end
And that should make a fairly accurate refuel function that tracks how much fuel you will need for the entire span (ie 2*z).
51 posts
Posted 08 October 2012 - 04:28 PM
Error is bios:206: [string "Mine" ] :7: '=' expected
so improved code is now
function checkFuel()
iFuelNow = turtle.getFuelLevel()
if iFuelNow <= z*2+2 then
turtle.select(16)
turtle.refuel(1)
iFuelNew = turtle.getFuelLevel()
if iFuelNew <= z*2+2 then
iFQuantum = iFuelNew - iFuelNow
iNeed = math.ceil((z*2+2 - iFuelNew)/iFQuantum)
turtle.refuel(iNeed)
end
end
end
Function moveback()
turtle.Back (8)
turtle.digDown ()
turtle.dig ()
turtle.Forward ()
turtle.Down ()
Tunnel (10)
loop
end
436 posts
Posted 08 October 2012 - 04:36 PM
First: I'm hoping the last few lines are pseudocode.
Second, I have no idea why it is throwing that error. Line 7 should be an if statement. Nothing is out of place that I can see. Unless <= doesn't work. Which I can't see why it wouldn't. On that off chance, make the if statement
if iFuelNew < z*2+3 then
Which is actually less memory usage, though generally inconsequentially.
EDIT:
Also, no capitals on the forward, back and down.
51 posts
Posted 08 October 2012 - 04:43 PM
used code
function checkFuel()
iFuelNow = turtle.getFuelLevel()
if iFuelNow <= z*2+2 then
turtle.select(16)
turtle.refuel(1)
iFuelNew = turtle.getFuelLevel()
if iFuelNew < z*2+3 then
iFQuantum = iFuelNew - iFuelNow
iNeed = math.ceil((z*2+2 - iFuelNew)/iFQuantum)
turtle.refuel(iNeed)
end
end
end
Function moveback()
turtle.back (8)
turtle.digDown ()
turtle.dig ()
turtle.forward ()
turtle.down ()
Tunnel (10)
loop
end
Same error but line 15
436 posts
Posted 08 October 2012 - 04:46 PM
……………………
I have no idea. So far as I can tell, there's nothing ther- Hang on.
Well I don't know this is actually a problem, but. . . I've got nothing else until I can get back to my CC world when I get home:
No spaces on function calls.
51 posts
Posted 08 October 2012 - 04:49 PM
fixed it was a F not a f got error on 23 the word end do i need more ends?
436 posts
Posted 08 October 2012 - 04:56 PM
No. . . But again, the last two lines prior to that end are not actual lines of code.
For tunnel, you want shell.run("tunnel", "10"), and for loop, well that one's a bit different. More or less because you need to actually craft a loop for it. If you want it to go on forever, then an while true do is in order, probably as the first line of the function. Then you will need another end at the end of the function.
51 posts
Posted 08 October 2012 - 04:57 PM
thanks ill remove the loop and just keep typing it in to the turt
51 posts
Posted 08 October 2012 - 04:59 PM
no errors but it dosent run
436 posts
Posted 08 October 2012 - 05:03 PM
Well, it won't. You haven't told it to do anything yet. All you've done is create functions that can be called at any time (so long as the program is running).
If you want to test it out, add this line to the bottom of your while loop:
checkFuel()
and then this line below everything:
moveback()
But be prepared to grab your turtle, or crtl-t it.
51 posts
Posted 08 October 2012 - 05:05 PM
i dont have a while loop?
521 posts
Location
Stockholm, Sweden
Posted 08 October 2012 - 05:27 PM
First: I'm hoping the last few lines are pseudocode.
Second, I have no idea why it is throwing that error. Line 7 should be an if statement. Nothing is out of place that I can see. Unless <= doesn't work. Which I can't see why it wouldn't. On that off chance, make the if statement
if iFuelNew < z*2+3 then
Which is actually less memory usage, though generally inconsequentially.
EDIT:
Also, no capitals on the forward, back and down.
The correct form is =<
if iFuelNew =< z*2+3 then
You don't have to use < and then specialize one of the values.
436 posts
Posted 08 October 2012 - 05:41 PM
i dont have a while loop?
Ah. Well quick question then: are you calling these from somewhere? Because they still won't run without being called. from somewhere.
51 posts
Posted 08 October 2012 - 06:06 PM
fixed it all almost replaced your fuel code with
shell.run("refuel" , "2")
works fine how ever i needed to add turn left dig turn right turn right dig turn left but shell.run("turn", "right") gives me a error but shell.run("turn", "left dose not")
51 posts
Posted 08 October 2012 - 06:09 PM
ill take that back
function moveback()
turtle.digDown ()
turtle.down ()
shell.run("turn", "left")
turtle.dig
shell.run("turn", "right")
shell.run("turn", "right")
turtle.dig
shell.run ("turn", "left")
turtle.dig ()
turtle.forward ()
turtle.digDown ()
turtle.down ()
shell.run("tunnel" , "10")
shell.run("go" , "back" , "8")
only gives error on line 9
436 posts
Posted 08 October 2012 - 06:30 PM
turtle.dig requires () follow it.
Also, replace all your shell.run("turn")s with turtle.turnLeft() or turtle.turnRight(). Unless you are doing a whole bunch of turns at the same time, this is easier and less laggy.
51 posts
Posted 08 October 2012 - 06:37 PM
turtle.dig requires () follow it.
Also, replace all your shell.run("turn")s with turtle.turnLeft() or turtle.turnRight(). Unless you are doing a whole bunch of turns at the same time, this is easier and less laggy.
function checkFuel()
shell.run ("refuel", "all")
end
function moveback()
turtle.digDown ()
turtle.down ()
turtle.turnLeft()
turtle.dig
turtle.turnRight()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.forward ()
turtle.digDown ()
turtle.down ()
shell.run("tunnel" , "10")
shell.run("go" , "back" , "8")
end
checkFuel()
moveback()
still returns error 9
436 posts
Posted 08 October 2012 - 06:59 PM
You did not heed the first line of my last post.
turtle.dig is turtle.dig(). Emphasis on the parentheses.
51 posts
Posted 08 October 2012 - 07:06 PM
thats not line 9
436 posts
Posted 08 October 2012 - 07:11 PM
Does not matter. The error handler is not always the most accurate. It just returns where the program failed, ie when it noticed there was a problem, not where the problem actually is.
51 posts
Posted 08 October 2012 - 07:28 PM
ok thanks its fixed and has run a few flawless runs how do i add a how many times? option so that it asks?
436 posts
Posted 08 October 2012 - 07:56 PM
print("Run for How Long?")
cho = io.read()
if tonumber(cho) ~= nil then
nCho = tonumber(cho)
else
print("Not a number.")
error()
end
Then, to add a loop that will make it run that many times, use a for loop.
for x =1, nCho do
-- Code here
end
51 posts
Posted 08 October 2012 - 08:03 PM
Dont suppose you know how to get it to find its way back up the stair case?
436 posts
Posted 08 October 2012 - 08:08 PM
Not easily, no. There are a couple tutorials on it on youtube, if you search "Turtle AI computercraft". It's like third or fourth, if I remember correctly.
51 posts
Posted 08 October 2012 - 08:29 PM
whats the code to place all into a adjacent chest
so to place a ender chest and deposit all items then brake the chest would it be
turtle.select (16)
turtle.placeUp()
turtle.empty(all)
turtle.digUp()
end
436 posts
Posted 08 October 2012 - 08:37 PM
I don't know that empty is a function. It would be simplest, given that, to do this:
for e = 1, 15 do
turtle.select(e)
turtle.dropUp(turtle.getItemCount(e))
end
But otherwise, all good.
51 posts
Posted 08 October 2012 - 08:42 PM
ill give this a shot
function Chest()
turtle.select (16)
turtle.placeUp()
for e = 1, 15 do
turtle.dropUp(turtle.getItemCount(e))
turtle.digUp()
end
436 posts
Posted 08 October 2012 - 08:44 PM
Need another end to close the function.
51 posts
Posted 08 October 2012 - 08:55 PM
yh i frigged that when i got the error it just seems to drop the chest on the floor :/ any other ideas?
51 posts
Posted 08 October 2012 - 09:14 PM
seems the dropup spits the items out
436 posts
Posted 08 October 2012 - 09:16 PM
Eheh. I think between us we made a mistake.
function chest()
turtle.select(16)
for e = 1, 15 do
turtle.select(e)
turtle.dropUp(turtle.getItemCount(e))
end
turtle.select(16)
turtle.digUp()
end
51 posts
Posted 08 October 2012 - 09:20 PM
ill try it but wont the ender chest be picked back up into slot 1?
51 posts
Posted 08 October 2012 - 09:24 PM
turtle.placeUp() is missing?
51 posts
Posted 08 October 2012 - 10:01 PM
function chest()
turtle.select(1) turtle.placeUp()
turtle.select(2) turtle.dropUp()
turtle.select(3) turtle.dropUp()
turtle.select(4) turtle.dropUp()
turtle.select(5) turtle.dropUp()
turtle.select(6) turtle.dropUp()
turtle.select(7) turtle.dropUp()
turtle.select(8) turtle.dropUp()
turtle.select(9) turtle.dropUp()
turtle.select(10) turtle.dropUp()
turtle.select(11) turtle.dropUp()
turtle.select(12) turtle.dropUp()
turtle.select(13) turtle.dropUp()
turtle.select(14) turtle.dropUp()
turtle.select(15) turtle.dropUp()
turtle.select(16) turtle.dropUp()
turtle.digUp()
end
tested and working