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

room cleaner problem

Started by union_follower, 15 March 2012 - 06:09 AM
union_follower #1
Posted 15 March 2012 - 07:09 AM
I am having some problems on this for at least 3 days before giving up and asking to get help :P/>/>
I have finished making the computer terminal program but i am having problems with line 32 of the coding below i think because is has been saying "cleaners:4: attempt to call nil" no matter what i do to the whole program itself.


rednet.open("back")
term.clear()
term.setCursorPos(1,1)
main()
function main()
print("Welcome To The Union Cleaner Terminal")
print("-------------------------------------")
print("Password:")
pass = io.read()
if pass == ("cleanunion") then
access()
else
term.clear()
term.setCursorPos(1,1)
print("Wrong Password!")
textutils.slowPrint ("Rolling Back To Main Menu...")
sleep(3)
main()
end
end
function access()
term.clear()
term.setCursorPos(1,1)
print("Union Cleaners Terminal")
print("-------------------------------------")
print("Commands: 1  -  startclean")
sleep(1)
print ("		 2  -  abortclean")
sleep(1)
print ("		 3  -  stopclean")
print("Enter Command:")
comm = io.read()
if comm ==("1") then
print (" ")
com1()
elseif comm ==("2") then
com2()
elseif comm ==("3") then
com3()
else
term.clear()
term.setCursorPos(1,1)
print ("Invalid Command!")
sleep(3)
access()
end
end
function comm1()
rednet.send("17","start")
rednet.send("19","start")
term.clear()
term.setCursorPos(1,1)
print ("Command Executed...")
print ("Turtles Have Been Dispatched.")
sleep(3)
access()
end
function com2()
rednet.send("17","abort")
rednet.send("19","abort")
term.clear()
term.setCursorPos(1,1)
print ("Command Executed...")
print ("Turles Have Halted.")
access()
end
function com3()
rednet.send("17","cancel")
rednet.send("19","cancel")
term.clear()
term.setCursorPos(1,1)
print ("Command Executed...")
print ("Turtles Are Now Going Back to Terminal.")
access()
end


I am also having problems with this code which is a unfinished turtle program that comes with the top of this post:

main()
function main()
turtle.detect()
if det == ("true")then
goout()
else
main()
end
function goout()
turtle.dig()
turtle.forward()
turtle.forawrd()
turtle.turnright()
end
end
Which keeps saying "cleaner:1:attempt to call nil…..
this coding is driving me nuts :)/>/> :)/>/> :D/>/>

(To think i even know how to make a decent program in C#………………..Im so pathetic ;)/>/> )

If anybody can help it would be greatly appreciated
And i would also appreciate if you tell me what is the problem with my coding so i dont bother all of you again…….

Cheers!!!
Liraal #2
Posted 15 March 2012 - 07:16 AM
you have to declare functions (e.g. by defining them) BEFORE you use them and you don't have to use main() at all.
just move all the functions to the top (i.e. before you call them) and it'll be all good.
petrus4 #3
Posted 15 March 2012 - 08:16 AM
As a general principle, using numerics for commands is also a bad idea. The machine won't have trouble keeping track of what the numbers mean, but your brain will. Write code that you can read.