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

[Question] My server doesn't use fuel. Is there an easy way to adapt programs?

Started by Paksarra, 12 March 2013 - 05:12 AM
Paksarra #1
Posted 12 March 2013 - 06:12 AM
There are some turtle programs I'd like to use that are written assuming that fuel is in use. (http://pastebin.com/zkb4FY4L is the first one, but there are a few others I'd like to use.) Right now it seems like using the function that checks if a turtle has fuel with fuel disabled will cause the program to crash with an error message. (I'm not sure if this is a bug in Computercraft or Working As Intended.)

The server I'm on has the turtles configured to not use fuel, and one of the admins is dead set against "wasting" rare and valuable resources like charcoal on fueling turtles. His reply to my inquiry on this breaking compatibility was was "just comment out the fuel subroutine in the program, then."

Easier said than done, as the program I'm looking to adapt first checks the fuel at pretty much every step, and I don't know LUA– it's transparent enough that I can see how the program works, but I don't know how to actually write LUA. To do this properly, I think I need to work out how to fix the logic that checks both the fuel level and if there's a block in the way. (I'm not asking for someone to rewrite this program for me if that's the only thing that will work; I'd rather be able to do it myself for any other fuel-using programs I might want to use, and the best way to learn is to do it.I'll be experimenting with it this evening.)

Is there an easier way to make programs that use fuel in general work on this server without having to rewrite them? For example, is there a line I could add at the start that says the turtle has ten million fuel and check that instead of what's in the inventory, and leave the rest of the program as it is?

Thank you for your time. :)/>/>
Lyqyd #2
Posted 12 March 2013 - 06:32 AM
Split into new topic.


function turtle.getFuelLevel()
  return 1000000000
end
Bubba #3
Posted 12 March 2013 - 07:25 AM
To expand upon Lyqyd's reply in case you were wondering about it, he is essentially just replacing the default turtle.getFuelLevel() function with a new one that always returns the same value. You should place the function at the very top of the program for it to work. The reason that your program is failing is that it expects a number where turtle.getFuelLevel() on a server without fuel will return "infinite" (a string value).
Paksarra #4
Posted 12 March 2013 - 07:43 AM
Thank you for the very, very prompt reply! I'd hoped something like that existed.

(I still sort of want to learn LUA now, but this will be good for the time being.)