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

Wireless Turtle Quarry

Started by grand_mind1, 12 December 2012 - 11:18 AM
grand_mind1 #1
Posted 12 December 2012 - 12:18 PM
I have a turtle that controls a lot of functions of my base. This particular turtle controls my turtle quarry. This is the startup program:

function check()
  if (message) == "Quarry" then
	shell.run("Quarry")
  else
	rednet.send(8, "Computer "..id.." tried to activate me!")
	print("Computer " ..id.." tried to activate me!")		
end				   --I thought this was the end for the function
rednet.open("right")
id, message = rednet.receive()
if (id) == 20 then
  check()
else
   print("Computer "..id.." tried to activate me!")
   rednet.send(8, "Computer "..id.." tried to activate me!")
end
What I am trying to get this program to do is listen for rednet signals from computer #8 and a certain message. If a different computer tries to activate the program it will print it on the screen and(if the computer is listening) send the same message to computer #8. I am new to functions and wanted to try to use them, but when I try to run this it gives me this error:

bios:338: [string "startup"]:16: 'end'
expected (to close 'function' at line
1)
I am new to Lua and know that I probably made a mistake somewhere that is very simple for a pro.
Feedback is appreciated!
Thanks! :D/>
n1ghtk1ng #2
Posted 12 December 2012 - 12:51 PM
You're missing an end. This should fix it :

function check()
  if (message) == "Quarry" then
	    shell.run("Quarry")
  else
	    rednet.send(8, "Computer "..id.." tried to activate me!")
	    print("Computer " ..id.." tried to activate me!")			  
end							    --I thought this was the end for the function
rednet.open("right")
id, message = rednet.receive()
if (id) == 20 then
  check()
else
   print("Computer "..id.." tried to activate me!")
   rednet.send(8, "Computer "..id.." tried to activate me!")
end
end
grand_mind1 #3
Posted 12 December 2012 - 02:12 PM
You're missing an end. This should fix it :

function check()
  if (message) == "Quarry" then
		shell.run("Quarry")
  else
		rednet.send(8, "Computer "..id.." tried to activate me!")
		print("Computer " ..id.." tried to activate me!")			  
end								--I thought this was the end for the function
rednet.open("right")
id, message = rednet.receive()
if (id) == 20 then
  check()
else
   print("Computer "..id.." tried to activate me!")
   rednet.send(8, "Computer "..id.." tried to activate me!")
end
end
After doing this the program doesn't wait for a message. I thought the rednet.receive() should wait for a signal until it gets one. When I run the program it just does nothing. Have I done something else wrong?
BrolofTheViking #4
Posted 12 December 2012 - 03:01 PM
What happened is you didn't end your If statement.
Well, you actually did end you if statement, but it was when you tried to end your function.
What you need is this.


function check()
  if (message) == "Quarry" then
		shell.run("Quarry")
  else
		rednet.send(8, "Computer "..id.." tried to activate me!")
		print("Computer " ..id.." tried to activate me!")	  
  end   --"this is what was missing"  
end							  
rednet.open("right")
id, message = rednet.receive()
if (id) == 20 then
  check()
else
   print("Computer "..id.." tried to activate me!")
   rednet.send(8, "Computer "..id.." tried to activate me!")
end

what the other suggestion, putting an end at the end of the code, had done was put the everything in the else statement, causing the computer to not do anything, because the entire code was part of the function check(), and that function was never called.
grand_mind1 #5
Posted 12 December 2012 - 03:29 PM
Wow. I feel really dumb right now. Well thanks for the feedback.