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

Help whit the Read() command.

Started by Nemesison, 07 January 2013 - 12:45 AM
Nemesison #1
Posted 07 January 2013 - 01:45 AM
Hi guy's i have just started programming whit computercraft and i have a problem with one of the programs that i'm making.

I want a turtle to check it's fuel level and if it's too low refuel herself with somethink in it's inventory.

Now the problem is that i don't know how to make the program make a variable out of the numeric response of the turtle.getFuelLevel() command, or in general whatever i want it to read that is not user imput.

Thanks in advance for the answers.

Edit: I've just realized that i may be in the wrong section, sorry if that is the case.
theoriginalbit #2
Posted 07 January 2013 - 02:30 AM
I do suggest that you read through the Lua documentation ( its VERY helpful ) as well as ComputerCraft documentation on how to program with Lua. Would would find that variables can accept any data type so you can just assign the return value of turtle.getFuelLevel() into a variable the same way you would anything else. However for this use case you wouldn't even need to store it in a variable, you could just put it in an 'if' or a loop…


if turtle.getFuelLevel() < someNumber then
or

while turtle.getFuelLevel() < someNumber do
remiX #3
Posted 07 January 2013 - 02:30 AM

currentFuel = turtle.getFuelLevel()
print(currentFuel)
Nemesison #4
Posted 07 January 2013 - 03:04 AM
It wordked, Thanks!