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

Program Ending When it Shouldn't.

Started by applesauce10189, 23 April 2014 - 11:40 AM
applesauce10189 #1
Posted 23 April 2014 - 01:40 PM
I have a program called "Check" because in a single player world I'm practicing with lua so I have a house controlled with computers and stuff and this is a program for checking if needed computers are online, for some reason it breaks the loop and ends the code but I don't have a break in it.


print("Green level system check.")
print("For higher level system checks please check")
print("from said levels.")
print("Type 'check' to check green level systems.")
while true do
  local input = read()
  if input == "check" then
	textutils.slowPrint("Checking systems...")
	rednet.broadcast("gdcheck")
	local did, dmessage = rednet.recieve(5)
	if not dmessage then
	  print("Error: Door offline.")
	end
	rednet.broadcast("glcheck")
	local lid, lmessage = rednet.recieve(5)
	if not lmessage then
	  print("Error: Light system offline.")
	end
  else
	print("Type 'check' to check green level systems.")
	print("Go to a higher level to check higher level")
	print("systems.")
  end
  if dmessage == "gdgood" then
	print("Green door online.")
  end
  if lmessage == "glgood" then
	print("Green lights online.")
  end
end
Note: It's probably worth noting I don't use rednet.open("side") because the computer this runs on uses the new bg function in startup to run multiple programs, one of which already opens a wireless modem on the back.

EDIT: fixed a couple spelling errors. I can never spell receive right. Now it just does the slow print "Checking systems…" and restarts from the beginning of the loop.
Edited on 23 April 2014 - 12:56 PM
Bomb Bloke #2
Posted 23 April 2014 - 03:46 PM
Making eg "dmessage" local to the "if input == "check" then" block means that your later checks won't be able to see it. Ditto for "lmessage".
applesauce10189 #3
Posted 23 April 2014 - 05:32 PM
Thanks, that was confusing me.