64 posts
Posted 21 November 2014 - 09:51 PM
I made a cobble generator program. The turtle sits facing where the cobble generates (from lava hitting water), and there is a chest behind the turtle.
I get an error when I run it:
bios:366: [string "cobgen"]:3: 'do' expected
I just dont see the error. Another set of eyes might help. Thanks !
-- Cobblestone Generator program
endearlyflag = 0
while endearlyflag=0 do
if turtle.detect()=="true" then -- there is cobble to grab
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 10 then -- if there is less than 65 fuel in the turtle...
itct = turtle.getItemCount(16)
if itct>0 then -- if there is at least 1 item in coal-slot 16...
turtle.select(16) -- choose slot 16 on turtle
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
end
else
-- out of fuel, stop program
endearlyflag = 1
end
if endearlyflag = 0 then
-- since there is fuel and cobble to grab then grab it
turtle.dig()
-- now if we have collected a stack (64) of cobble, put it in the chest
-- PUT IF STATEMENT IN HERE TO CHECK FOR STACK BEFORE EXECUTING !!!!!!!!!!!!!
turtle.turnRight()
turtle.turnRight()
turtle.drop()
turtle.turnRight()
turtle.turnRight()
end
end
end
1220 posts
Location
Earth orbit
Posted 21 November 2014 - 09:56 PM
On line 3, change…
while endearlyflag = 0
to…
while endearlyflag == 0
Note the double equals - that's a comparitor - with the single equals, you were trying to set endearlyflag to 0. Not sure if you were already aware of this and just missed it or not, but there it is :)/>
Edited on 21 November 2014 - 08:57 PM
1023 posts
Posted 21 November 2014 - 10:05 PM
Line 17 will throw a similar error from the same problem.
change
if endearlyflag = 0 then
to
if endearlyflag == 0 then
Edited on 21 November 2014 - 09:06 PM
64 posts
Posted 22 November 2014 - 01:33 PM
I fixed that problem but I appear to have a "logic problem". The program runs but does nothing. Not sure why. Any help would be appreciated…
-- Cobblestone Generator program
endearlyflag = 0
while endearlyflag==0 do
if turtle.detect()=="true" then -- there is cobble to grab
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 10 then -- if there is less than 65 fuel in the turtle...
itct = turtle.getItemCount(16)
if itct>0 then -- if there is at least 1 item in coal-slot 16...
turtle.select(16) -- choose slot 16 on turtle
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
end
else
-- out of fuel, stop program
endearlyflag = 1
end
if endearlyflag == 0 then
-- since there is fuel and cobble to grab then grab it
turtle.dig()
-- now if we have collected a stack (64) of cobble, put it in the chest
cobct = turtle.getItemCount(1)
if cobct>63 then
turtle.turnRight()
turtle.turnRight()
turtle.drop()
turtle.turnRight()
turtle.turnRight()
end
end
end
end
7083 posts
Location
Tasmania (AU)
Posted 22 November 2014 - 01:51 PM
"true" and true
are not the same.
64 posts
Posted 22 November 2014 - 02:19 PM
Ok, I removed the quotes from true, and the program no longer locks up, but …
but now the program appears to run through and do nothing. It does not even fuel up.
There is still a flaw in the logic that I do not see. Help ?
1023 posts
Posted 22 November 2014 - 04:38 PM
-- Cobblestone Generator program
endearlyflag = 0
while endearlyflag==0 do
if turtle.detect()=="true" then -- there is cobble to grab
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 10 then
itct = turtle.getItemCount(16)
if itct>0 then -- if there is at least 1 item in coal-slot 16...
turtle.select(16) -- choose slot 16 on turtle
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
else
-- out of fuel, stop program
endearlyflag = 1
end
end
if endearlyflag == 0 then
-- since there is fuel and cobble to grab then grab it
turtle.dig()
-- now if we have collected a stack (64) of cobble, put it in the chest
cobct = turtle.getItemCount(1)
if cobct>63 then
turtle.turnRight()
turtle.turnRight()
turtle.drop()
turtle.turnRight()
turtle.turnRight()
end
end
end
end
On line 12 you end the if statement, which checks if there is coal in the 16th slot. Because of this the else statement right below it goes to the if statement that checks if the turtle has less than 10 fuel left. This means that if the turtle has MORE than 10 fuel it will run that else statement, which will change the endearlyflag variable. This will cause the while statement to stop, and the if statement that actually causes the program to do stuff not to return true.
The code above, which I posted corrects that error.
Edited on 22 November 2014 - 03:39 PM
64 posts
Posted 22 November 2014 - 04:48 PM
Now the program does nothing. I have to use Ctrl-T to terminate it, and it does not dig the cobble.
1023 posts
Posted 22 November 2014 - 04:52 PM
Now the program does nothing. I have to use Ctrl-T to terminate it, and it does not dig the cobble.
ahh sorry i copied and pasted the code from above, which still has the "true" error
-- Cobblestone Generator program
endearlyflag = 0
while endearlyflag==0 do
if turtle.detect()==true then -- there is cobble to grab
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 10 then
itct = turtle.getItemCount(16)
if itct>0 then -- if there is at least 1 item in coal-slot 16...
turtle.select(16) -- choose slot 16 on turtle
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
else
-- out of fuel, stop program
endearlyflag = 1
end
end
if endearlyflag == 0 then
-- since there is fuel and cobble to grab then grab it
turtle.dig()
-- now if we have collected a stack (64) of cobble, put it in the chest
cobct = turtle.getItemCount(1)
if cobct>63 then
turtle.turnRight()
turtle.turnRight()
turtle.drop()
turtle.turnRight()
turtle.turnRight()
end
end
end
end
64 posts
Posted 22 November 2014 - 05:09 PM
Ah. that did it. Thanks!