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

[help] this code is right!

Started by LuaEclipser, 09 March 2013 - 03:58 PM
LuaEclipser #1
Posted 09 March 2013 - 04:58 PM
i don't know what is wrong with this code, it says it expects end to close for but there is an end!


function sf(args)
    gas = turtle.getFuelLevel()
    if args < gas then
        for i=1, args do
        turtle.forward()
            else
            print("no fuel")

        [size=4]end[/size]
    end
end

Please tell me the error! thank you
MudkipTheEpic #2
Posted 09 March 2013 - 05:02 PM
REmove an end from the end and put it before the else.
SuicidalSTDz #3
Posted 09 March 2013 - 05:04 PM
Ah, my eyes. It burns! Poor indentation.. can't breathe.. help me immibis!
Lyqyd #4
Posted 09 March 2013 - 05:05 PM

function sf(args)
    gas = turtle.getFuelLevel()
    if args < gas then
        for i=1, args do
            turtle.forward()
        end
    else
        print("no fuel")
    end
end
LuaEclipser #5
Posted 09 March 2013 - 05:16 PM
thank you, and yes i know, i dont really understand the indenting
SuicidalSTDz #6
Posted 09 March 2013 - 05:20 PM
Indentation deprivation!
3LiD #7
Posted 09 March 2013 - 05:20 PM

function checkFuel(arg1)
if type(arg1) == "number" then
  local fuel1, fuel2 = turtle.getFuelLevel()
  if fuel1 >= arg1 then
   return true
  else
   return false
  end
else
  return false
end
end

Will return if you can move the ammount of blocks you said in arg1… Will return true for can move or false if it cant or the input isnt a integer.



(Not Tested)
LuaEclipser #8
Posted 09 March 2013 - 05:27 PM
ok new error, it says a nil value when i try to run the function help?
3LiD #9
Posted 09 March 2013 - 05:29 PM
Try this..


function checkFuel(arg1)
local fuel1, fuel2 = turtle.getFuelLevel()
if fuel1 >= arg1 then
  return true
else
  return false
end
end
ChunLing #10
Posted 09 March 2013 - 05:31 PM
What line?

Also, provide the current code of the function you're trying to use.
Edited on 09 March 2013 - 04:33 PM