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

wifi piston menu code startup:84:attempt to call nil error

Started by fizzy6868, 29 July 2012 - 01:31 AM
fizzy6868 #1
Posted 29 July 2012 - 03:31 AM
wifi piston menu code startup:84:attempt to call nil error
hello all i am new to computercraft and have been messing about with it for the last few day i know a little vb and c# but this has stumped me the pistons open and close open is fine but when i close them it crashes hope some one can help me here is code for doors and menu ohhh and i am using ComputerCraft1.33 minecraft 1.2.5 thanks sooo much if you can help
menu code id 6

rednet.open("top")
x = "test"
while x ~= "exit" do
------main
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "|Welcome please type command below|"
print "|								 |"
print "|1 = station gates				|"
print "|								 |"
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
x = io.read()
if x == "1" then
term.clear()
term.setCursorPos(1,1)
   y = "test"
while y ~= "exit" do
------station gates
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "|		Station gate			 |"
print "|		   access				|"
print "|								 |"
print "|   1 = open	   2 = close	  |"
print "|	   exit = main menu		  |"
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
y = io.read()

---open
  if y == "1" then
  
	term.clear()
	term.setCursorPos(1,1)
	rednet.send(10, "open")
  
  id,message = rednet.receive(10)
   if  id == 10 and message == "open" then
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "	   station gate 1 open		 "
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
	end  
	rednet.send(11, "open")
  id,message = rednet.receive(10)
   if id == 11 and message == "open" then
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "	   station gate 2 open		 "
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
   end
  
   sleep(2)
   term.clear()
   term.setCursorPos(1,1)
end
if y == "2" then
rednet.send(10, "closed")
id,message = rednet.receive(10)
if id == 10 and message == "closed" then
print("worked")
end
rednet.send(11, "closed")
id,message = rednet.recieve(1)
if id == 11 and message == "closed" then
print("worked")
end
end
end
end
end

Piston door one id 10

side = "back"
rednet.open(side)
function clear()
	term.clear()
	term.setCursorPos(1,1)
end
clear()
while true do
event, param1, param2 = os.pullEvent("rednet_message")
----on
if param2 == "open" then
print("i am on")
rednet.send(6, "open")
redstone.setOutput("left",false)
end
----off
if param2 == "closed" then
print("i got stopped")
rednet.send(6, "closed")
redstone.setOutput("left", true)
end
----check
if param2 == "check" then
   if redstone.getOutput("left") == false then
	print("got check")
	rednet.send(8, "open")
   end
   if redstone.getOutput("left") == true then
	print("got check")
	rednet.send(8, "closed")
   end
end

end
clear()

piston door two id 11

side = "bottom"
rednet.open(side)
function clear()
	term.clear()
	term.setCursorPos(1,1)
end
clear()
while true do
event, param1, param2 = os.pullEvent("rednet_message")
----open
if param2 == "open" then
print("i am on")
rednet.send(6, "open")
redstone.setOutput("left",false)
end
----close
if param2 == "closed" then
print("i got stopped")
rednet.send(6, "closed")
redstone.setOutput("left", true)
end
----check
if param2 == "check" then
   if redstone.getOutput("left") == false then
	print("got check")
	rednet.send(8, "open")
   end
   if redstone.getOutput("left") == true then
	print("got check")
	rednet.send(8, "closed")
   end
end

end
clear()
sjele #2
Posted 29 July 2012 - 08:29 AM
Is the code posted in the order it sits in or have you cut out parts?
Since you cut it up means it much harder to find line 84
fizzy6868 #3
Posted 29 July 2012 - 02:31 PM
Is the code posted in the order it sits in or have you cut out parts?
Since you cut it up means it much harder to find line 84
hey thanks for replying the error is in the menu code the other to are the doors of you want to try it for yourself
sjele #4
Posted 29 July 2012 - 03:01 PM
Is it ment to have a thingy infront of = on line 3? Or is it suposed to be like this


while x == "exit" do
while x == "exit" then
fizzy6868 #5
Posted 29 July 2012 - 03:28 PM
i see what you mean but the ~= means not equal to so it loops
so when i type exit it will go bk to last menu
fizzy6868 #6
Posted 29 July 2012 - 03:35 PM
it is something to do with the closing the pistons function on the menu code if I open it, it works fine but when I close the pistons it closes the program and give me this startup:84:attempt to call nil
sjele #7
Posted 29 July 2012 - 03:47 PM
I see what error is now. When you comment out stuff use – not —- as you used, so the error means it is trying to call the line that says —-on etc.

So i think this code would work:
Menu:
Spoiler

rednet.open("top")
x = "test"
while x ~= "exit" do
--main
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "|Welcome please type command below|"
print "|																 |"
print "|1 = station gates							   |"
print "|																 |"
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
x = io.read()
if x == "1" then
term.clear()
term.setCursorPos(1,1)
   y = "test"
while y ~= "exit" do
--station gates
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "|			    Station gate					 |"
print "|				   access							   |"
print "|																 |"
print "|   1 = open	    2 = close	  |"
print "|		   exit = main menu			   |"
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
y = io.read()
--open
  if y == "1" then
 
	    term.clear()
	    term.setCursorPos(1,1)
	    rednet.send(10, "open")
 
  id,message = rednet.receive(10)
   if  id == 10 and message == "open" then
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "    station gate 1 open		   "
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
	    end 
	    rednet.send(11, "open")
  id,message = rednet.receive(10)
   if id == 11 and message == "open" then
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
print "    station gate 2 open		   "
print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
   end
 
   sleep(2)
   term.clear()
   term.setCursorPos(1,1)
end
if y == "2" then
rednet.send(10, "closed")
id,message = rednet.receive(10)
if id == 10 and message == "closed" then
print("worked")
end
rednet.send(11, "closed")
id,message = rednet.recieve(1)
if id == 11 and message == "closed" then
print("worked")
end
end
end
end
end
SpoilerDoor 1:

side = "back"
rednet.open(side)
function clear()
	    term.clear()
	    term.setCursorPos(1,1)
end
clear()
while true do
event, param1, param2 = os.pullEvent("rednet_message")
--on
if param2 == "open" then
print("i am on")
rednet.send(6, "open")
redstone.setOutput("left",false)
end
--off
if param2 == "closed" then
print("i got stopped")
rednet.send(6, "closed")
redstone.setOutput("left", true)
end
--check
if param2 == "check" then
   if redstone.getOutput("left") == false then
	    print("got check")
	    rednet.send(8, "open")
   end
   if redstone.getOutput("left") == true then
	    print("got check")
	    rednet.send(8, "closed")
   end
end
end
clear()

SpoilerDoor 2

side = "bottom"
rednet.open(side)
function clear()
	    term.clear()
	    term.setCursorPos(1,1)
end
clear()
while true do
event, param1, param2 = os.pullEvent("rednet_message")
--open
if param2 == "open" then
print("i am on")
rednet.send(6, "open")
redstone.setOutput("left",false)
end
--close
if param2 == "closed" then
print("i got stopped")
rednet.send(6, "closed")
redstone.setOutput("left", true)
end
--check
if param2 == "check" then
   if redstone.getOutput("left") == false then
	    print("got check")
	    rednet.send(8, "open")
   end
   if redstone.getOutput("left") == true then
	    print("got check")
	    rednet.send(8, "closed")
   end
end
end
clear()
MysticT #8
Posted 29 July 2012 - 04:02 PM
Just a simple typo:

id,message = rednet.recieve(1)
should be:

id,message = rednet.receive(1)
fizzy6868 #9
Posted 29 July 2012 - 04:47 PM
thanks so much
sjele


and

MysticT


i think it was the silly typo the annoying thing is i have just retyped the hole lot and it worked wish I check here a few mins earlier
i never seen it thanks