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

[question][lua] safe forward turtle?

Started by LuaEclipser, 09 March 2013 - 11:31 AM
LuaEclipser #1
Posted 09 March 2013 - 12:31 PM
I know im asking so many questions, but im working on my * cough* wait…….. not announced yet XD

But I want to know how to make a turtle check for fuel, and say not enough fuel if not enough fuel. if true, go forward
i have tried numerous different ways.

Thank you!
SuicidalSTDz #2
Posted 09 March 2013 - 12:33 PM
I know im asking so many questions, but im working on my * cough* wait…….. not announced yet XD

But I want to know how to make a turtle check for fuel, and say not enough fuel if not enough fuel. if true, go forward
i have tried numerous different ways.

Thank you!
Please look on the wiki before posting topics that can be answered there
Conn332 #3
Posted 09 March 2013 - 12:33 PM
turtle.getFuelLevel()
LuaEclipser #4
Posted 09 March 2013 - 12:36 PM
i have tried turtle.getfuel() but i need it to add up the actions i give it (such as turtle.forward(4) turtle.back(5) and let me know if possible
BTW, i have a turtle.forward(args) function
SuicidalSTDz #5
Posted 09 March 2013 - 12:37 PM
turtle.getFuelLevel()
See, now why did you go tell him that :P/> He has two hands (Im guessing) so he can click that link and find out all he needs to know about the Turtle API. Oh well, problem solved either way.

i have tried turtle.getfuel() but i need it to add up the actions i give it (such as turtle.forward(4) turtle.back(5) and let me know if possible
BTW, i have a turtle.forward(args) function
You did not tell us you needed to do that. That is something that should go in the OP, not a seperate post.
3ydney #6
Posted 09 March 2013 - 12:42 PM
It depends on what type of fuel your using for the formula. If using coal the forumal would be: (a = ammount of coal)

a x 8 = b (b = places that can the turtle can move…)


Here is some code..


function moveCount()
local f = turtlegetFuelLevel()
local v = tonumber(f*8)
return v
end

It will return how many block spaces you can move.

THIS ONLY WORKS WITH COAL… BUT I CAN REWRITE IT FOR A DIFFERENT FUEL
LuaEclipser #7
Posted 09 March 2013 - 12:42 PM
will this work?



function s.f(args)
    gas = turtle.getFuelLevel()
    if args < gas then
       for i=1, args do 
       turtle.forward()
    else
    print("No Fuel")
    fuel = no
[size=4]end[/size]

thank you for answering so many questions :P/>
3ydney #8
Posted 09 March 2013 - 12:44 PM
I dont know… Test it..
SuicidalSTDz #9
Posted 09 March 2013 - 12:44 PM
Instead of doing the above, just calculate the fuel level by doing this:

>lua
>turlte.getFuelLevel()
–Fuel level
>exit()
–Run program
>lua
>turtle.getFuelLevel()
–Now subtract the two and that is how much fuel you will need
LuaEclipser #10
Posted 09 March 2013 - 12:46 PM
i want it in my program, super turtle. its a huge thing *DID I JUST RELEASE XDXDXD*
not to type it in the Lua prompt :P/>
SuicidalSTDz #11
Posted 09 March 2013 - 12:47 PM
i want it in my program, super turtle. its a huge thing *DID I JUST RELEASE XDXDXD*
not to type it in the Lua prompt :P/>
-.- I was walking you through the steps to detect the fuel level manually… Not automatically
LuaEclipser #12
Posted 09 March 2013 - 12:48 PM
i want it in my program, super turtle. its a huge thing *DID I JUST RELEASE XDXDXD*
not to type it in the Lua prompt :P/>
-.- I was walking you through the steps to detect the fuel level manually… Not automatically
if i need it in the future, HUGS but now i dont
SuicidalSTDz #13
Posted 09 March 2013 - 12:51 PM
i want it in my program, super turtle. its a huge thing *DID I JUST RELEASE XDXDXD*
not to type it in the Lua prompt :P/>
-.- I was walking you through the steps to detect the fuel level manually… Not automatically
if i need it in the future, HUGS but now i dont
Blah! Read up on the turtle api, it'll save ye ;)/>