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

Errors in Control Program for Engine

Started by tyon2006, 27 November 2012 - 01:56 PM
tyon2006 #1
Posted 27 November 2012 - 02:56 PM
Hey Everyone. Making a control program for my omnidirectional inchworm engine. I have tested the engine extensively with levers and colored wire so I know its good, now i want to work on a program to control it automatically. I keep getting the "attempt to call nil" over and over on a lot of my lines. It either gives me an attempt to call nil error or it will crash when i enter the count input. Please advise? It gets to the 7th line from the bottom (give or take. ive made about 50 changes trying to troubleshoot this).

– Omnidirectional Control Panel –
–[[
Color Codes:
white:forward:1
black:right:32768
blue:left:2048
green:backward:8192
brown:up:4096
red:down:16384
]]–

function move(dir, cnt)
term.write("traveling")
col = 0

if dir == "fore" then
col = 1
elseif dir == "back" then
col = 8192
elseif dir == "left" then
col = 2048
elseif dir == "right" then
col = 32768
elseif dir == "up" then
col = 4096
elseif dir == "down" then
col = 16348
else
term.write("Incorrect Input. Try again")
do return end
end

while(cnt > 0) do
redstone.setBundledOutput("back", col)
sleep(0.75)
redstone.setOutput( "back", false )
sleep(0.75)
cnt=cnt-1
end
term.write("arrived")
end

term.clear()
term.setCursorPos(1,3)
textutils.slowPrint("Welcome to the Flutter Control Panel")
sleep(0.5)
term.clear()
term.setCursorPos(0,3)
textutils.slowPrint("Initializing")
sleep(0.5)
term.clear()

term.write("Please Choose from the following options:")
term.write("fore, back, left, right, up down")

while true do
term.print("enter a direction:")
local direction = read()
term.print("enter a count:")
local count = read()

move(direction,count)
end
Tiin57 #2
Posted 28 November 2012 - 01:07 AM
Line 20 or so; do return end
Should probably be return nil end
KaoS #3
Posted 28 November 2012 - 03:16 AM

while(cnt > 0) do
you must have a space after the 'while' or it tries to run it like a function and you will get an attempt to call nil error
tyon2006 #4
Posted 28 November 2012 - 02:07 PM
KaoS, The error is coming from ~line 57. The terminal prints "fore, back, left, right, up down" then immediately crashes with nil.
KaoS #5
Posted 28 November 2012 - 11:16 PM
ahah. term.print does not exist. just use print
Tiin57 #6
Posted 29 November 2012 - 12:58 AM

while(cnt > 0) do
you must have a space after the 'while' or it tries to run it like a function and you will get an attempt to call nil error
while is a keyword; it cannot be a function.