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

[Lua][Error]<Eof> expected, turtle remote program

Started by CastleMan2000, 08 July 2012 - 04:59 PM
CastleMan2000 #1
Posted 08 July 2012 - 06:59 PM
I'm having a problem while working on my turtle remote program.
Here's the code:

Computer (Master):

local function RCmaster(tid)
while true do
local sEvent, param = os.pullEvent("key")
if(sEvent == "key") then
if(param == 200) then
rednet.send(tid,"TRM:FORWARD")
elseif (param == 208) then
rednet.send(tid,"TRM:BACKWARD")
elseif (param == 203) then
rednet.send(tid,"TRM:TURNLEFT")
elseif (param == 205) then
rednet.send(tid,"TRM:TURNRIGHT")
elseif (param == 28) then
rednet.send(tid,"TRM:PLACEBLOCK")
elseif (param == 30) then
rednet.send(tid,"TRM:UP")
elseif (param == 44) then
rednet.send(tid,"TRM:DOWN")
end
end
end
end
local function init()
print("What side is your modem on?")
local modem = read()
rednet.open(modem)
print("What is the ID of the slave turtle?")
local tid = tonumber(read())
term.clear()
textutils.slowPrint("TurtleRemote Initiated.")
end
init()
print ("Arrow keys = Move, Enter = Place block, A = Move up, Z = Move down.")
RCmaster(tid)

Turtle (Slave):

local function init()
rednet.open("right")
term.clear()
textutils.slowPrint("TurtleRemoteSlave Initiated.")
end
local function RCslave()
while true do
local id, msg = rednet.receive()
if(msg == "TRM:FORWARD") then
print("Forward")
if(turtle.detect() == true) then
print("Block Detected. Digging.")
turtle.dig()
end
turtle.forward()
elseif(msg == "TRM:BACKWARD") then
print("Backward")
turtle.back()
elseif(msg == "TRM:TURNLEFT") then
print("Turn Left")
turtle.turnLeft()
elseif(msg == "TRM:TURNRIGHT") then
print("Turn Right")
turtle.turnRight()
elseif(msg == "TRM:PLACEBLOCK") then
if(turtle.detect() == true) then
print("ERROR:Block Present")
else
print("Place Block")
turtle.place()
end
elseif(msg == "TRM:UP") then
if(turtle.detectUp() == true) then
print("Block Detected. Digging.")
turtle.digUp()
print("Up")
turtle.up()
end
elseif(msg == "TRM:DOWN") then
if(turtle.detectDown == true) then
print("Block Detected. Digging.")
turtle.digDown()
end
print("Down")
turtle.down()
end
end
end
end
init()
RCslave()

The error:
"bios:206: [string"turtleremoteslave"]:49: '<eof>' expected"
when I try to run the turtle-side program, TurtleRemoteSlave.
KevinW1998 #2
Posted 08 July 2012 - 07:27 PM

local function init()
    rednet.open("right")
    term.clear()
    textutils.slowPrint("TurtleRemoteSlave Initiated.")
end
local function RCslave()
    while true do
        local id, msg = rednet.receive()
        if(msg == "TRM:FORWARD") then
            print("Forward")
            if(turtle.detect() == true) then
                print("Block Detected. Digging.")
                turtle.dig()
            end
            turtle.forward()
            elseif(msg == "TRM:BACKWARD") then
                print("Backward")
                turtle.back()
            elseif(msg == "TRM:TURNLEFT") then
                print("Turn Left")
                turtle.turnLeft()
            elseif(msg == "TRM:TURNRIGHT") then
                print("Turn Right")
                turtle.turnRight()
            elseif(msg == "TRM:PLACEBLOCK") then
                if(turtle.detect() == true) then
                print("ERROR:Block Present")
            else
            print("Place Block")
            turtle.place()
            end
        elseif(msg == "TRM:UP") then
            if(turtle.detectUp() == true) then
                print("Block Detected. Digging.")
                turtle.digUp()
                print("Up")
                turtle.up()
            end
        elseif(msg == "TRM:DOWN") then
            if(turtle.detectDown == true) then
            print("Block Detected. Digging.")
            turtle.digDown()
        end
        print("Down")
        turtle.down()
        end
    end
end
end -- A "end" too much
init()
RCslave()
You have a "end" too much!
CastleMan2000 #3
Posted 09 July 2012 - 12:29 AM
Thanks, I'll try it!
CastleMan2000 #4
Posted 10 July 2012 - 12:20 AM
It works, to fix the error, but for some reason I can't go down and it doesn't even register up.