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

My Code Wont Work

Started by TyDoesMC, 11 June 2013 - 02:45 PM
TyDoesMC #1
Posted 11 June 2013 - 04:45 PM

--My Second Code
--To use put this code in startup on the turtle
--Dont Edit anything unless your inproving the code
--This Is Sloppy I Know But Im New
--This Code Goes In The Turtle, and in a file called startup
--Use f, b, l, r, to drive it but you type: f, hit enter to go forward
-- f is forward, b is back, l is left, r is right.
yes = turtle.refuel(1)
fuel = turtle.getFuelLevel()
f = turtle.forward()
b = turtle.back()
l = turtle.turnLeft()
r = turtle.turnRight()
textutils.slowPrint("Checking Fuel...")
sleep(6)
turtle.getFuelLevel()
sleep(4)
textutils.slowPrint("Fuel Level: "..fuel.."")
write("Want To Refuel Turtle?: ")
Refuelturtle = read()
if Refuelturtle == (yes) then
textutils.slowPrint("Refueling Turtle...")
Sleep(5)
turtle.refuel()
textutils.slowPrint("Turtle Successfuly Refueled")
else
textutils.slowPrint("Refueling Cancled")
textutils.slowPrint("Turtle Is Ready To Go!")
Ready = read()
write("TCP: ")
if Ready == (f) then
..f..
textutils.slowPrint("Turtle Moving Forward")
sleep(2)
term.clear()
if Ready == (B)/>/> then
..b..
textutils.slowPrint("Turtle Moving Back")
sleep(2)
term.clear()
if Ready == (l) then
..l..
textutils.slowPrint("Turtle Moving Left")
sleep(2)
term.clear()
if Ready == (r) then
..r..
textutils.slowPrint("Turtle Moving Right")
sleep(2)
term.clear()
end

Why Wont it work and can you make it smaller?
Engineer #2
Posted 11 June 2013 - 05:02 PM
I see you are doing this:

l = turtle.forward()

..l..

l holds if turtle.forward() succeeded or not a that ..l.. Is what Im assuming a function call. You should use this:

l = turtle.forward

l()

I also want to point out it is way more polite to give some more information on what the purpose of this program is, what errors you are getting etc.

Now its just: here is my code, fix it.

I dont know if you are new since Im on a phone, but please do it the polite way next time.

Edit: I have also spotted that you are checking your Read variable to another variable. This will never be true. Since read() returns a string, you need to put qoutation marks:

Ready = read()
if Ready == 'turtle.forward' then
    l() -- from what I taught you earlier
end