4 posts
Posted 12 February 2014 - 02:53 AM
What I'm trying to do now is add a fuel checker/refueling bit into my mining code
local mf = 400
while true do
while turtle.getFuelLevel() < mf do
turtle.refuel(1)
end
end
function mine()
for m = 1,80 do
turtle.dig()
turtle.up()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
end
end
functin back(number)
for a = 1,number do
turtle.back()
end
end
mine()
back(80)
I would like the 2 functions there, but every time the program in run(my user, not automatic!), I want it to check for fuel, eat enough fuel, then mine, repeat and maybe not run if not enough fuel?
1281 posts
Posted 12 February 2014 - 11:04 AM
Just remove while true do loop, and you should be good to go.
Alternatively, you could throw in an error message instead of the constant loop, to halt the program if there is a lack of fuel
assert(turtle.getFuelLevel() < mf,"Not enough fuel!") -- assert will use the second argument as an error message, if the first argument is false or nil
4 posts
Posted 12 February 2014 - 04:32 PM
local mf = 80
while turtle.getFuelLevel() < mf do
turtle.refuel(1)
end
function mine(number)
for m = 1,number do
turtle.dig()
turtle.up()
turtle..dig()
turtle.forward()
turtle.turnRight()
end
end
function mine2(number)
for m = 1,number do
turtle.dig()
turtle.down()
turtle.dig()
turtle.turnLeft()
end
end
function back(number)
for b = 1,number do
turtle.back()
end
end
function minec(number)
for m = 1,number do
mine(1)
mine2(1)
end
end
function minef(number)
for m = 1,number do
minec(9)
mine(1)
place(1)
mine2(1)
end
end
minef(10)
back(80)
towards the end it was just turning left then right, I have zero idea why. also idk if I can use "m" as many times as I do? (for m = 1,number do)
also ingame it is a pain to type on that screen, is there a way around? also for my place function, I can put my torches in slot 2? and the 1 in getFuel(1) is to select slot 1? how often does it refuel programmed like this?
1281 posts
Posted 12 February 2014 - 04:44 PM
the iterator variable will always be local to the loop it's created for. This means you can reuse the same name however many times you wish.Though it is bad practice, the only drawback is that you can't acess the variable of any other loops using the same variable name from the currently running loop.
There's loads of options avilable for coding outside of the game, personally i use pastebin.com along with the in-game pastebin program.
See this thread for more info
http://www.computercraft.info/forums2/index.php?/topic/17025-writing-my-code-using-different-programs/The code you posted has no place function, so i can't really help you there, AS for the getFuel, i assume you mean refuel, as getFuel dosen't take any arguments. turtle.refuel accepts one number argument, which is how many items in the selected slot to use for fuel. to select what slot to use, you need to first use turtle.select(slotNum)
http://computercraft.info/wiki/Turtle_%28API%29Currently it will only refuel at the start of the program.