Jump to content




Program Ending When it Shouldn't.


  • You cannot reply to this topic
2 replies to this topic

#1 applesauce10189

  • Members
  • 162 posts

Posted 23 April 2014 - 12: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 by applesauce10189, 23 April 2014 - 01:56 PM.


#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 23 April 2014 - 02: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".

#3 applesauce10189

  • Members
  • 162 posts

Posted 23 April 2014 - 04:32 PM

Thanks, that was confusing me.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users