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

[SOLVED] Monitor Not Displaying in Program

Started by Noiro, 02 June 2013 - 08:11 PM
Noiro #1
Posted 02 June 2013 - 10:11 PM
Alright, in the second function, it is supposed to keep me updated on the status of the AE network. Sending works fine and that thread works fine (I had it print to computer screen every time it got a message.)
In a test program, I can write to the monitor of the same side. In this program, I can tell it to write to the monitor anywhere in the code and no-go. Any ideas as to what stupid thing I"m missing? No errors show up. I just can't get text to stay on the monitor beside the computer. >.<
http://pastebin.com/rKGS7E91

Spoiler

	rednet.open("left")
	monitor = peripheral.wrap("right")
	monitor.clear()
	monitor.write("Test") --This part fails.
	
	function sendData()
	  while true do
		shell.run("clear")
		print("You can turn on and off AE grid here:")
		tosendData = read()
	
	  if tosendData == "off" or tosendData == "OFF" then
		print("Cutting off AE power grid...")
		rednet.send(1,"off")
		print("Looking for response...")
		id,message = rednet.receive(1)
		if message == "ack" then
		  print("Power system has been cut off!")
		  sleep(2)
		end
	  
	  elseif tosendData == "on" or tosendData == "ON" then
		print("Turning on AE power grid...")
		rednet.send(1,"on")
		id,message = rednet.receive(1)
		if message == "ack" then
		  print("Power system has been turned on!")
		  sleep(2)
		else
		  print("Retrying one more time...")
		  rednet.send(1,"on")
		  id,message = rednet.receive()
		  if message == "ack" then
			print("Power system has been turned on!")
			sleep(2)
		  else
			print("Message failed. Please try again.")
			sleep(2)
		  end
		end
	  else
		print("That's not a possible option.")
		sleep(2)
	end
	sleep(.1)
		end
	end
	
	function getAEPower()
	 while true do
		who,message = rednet.receive()
	  if message == "on" then
		monitor.clear()
		monitor.write("AE Power: ON")
	  elseif message == "off" then
		monitor.clear()
		monitor.write("AE Power: OFF")
	  end
	  sleep(.1)
	 end
	end
	
	shell.run("clear")
	print("Starting up Client...")
	parallel.waitForAll(sendData, getAEPower)

BigSHinyToys #2
Posted 02 June 2013 - 10:29 PM
My guess with out testing btw is that the sleep is causing received messages to be ignored. You only need one yield in a coroutine for it to work with out the "too long with out yield error" and the rednet.receive has one in it.

function getAEPower()
while true do
    who,message = rednet.receive()
  if message == "on" then
    monitor.clear()
    monitor.write("AE Power: ON")
  elseif message == "off" then
    monitor.clear()
    monitor.write("AE Power: OFF")
  end
  sleep(.1) -- remove this and see if it works
end
end
Noiro #3
Posted 02 June 2013 - 10:32 PM
My guess with out testing btw is that the sleep is causing received messages to be ignored. You only need one yield in a coroutine for it to work with out the "too long with out yield error" and the rednet.receive has one in it.

function getAEPower()
while true do
	who,message = rednet.receive()
  if message == "on" then
	monitor.clear()
	monitor.write("AE Power: ON")
  elseif message == "off" then
	monitor.clear()
	monitor.write("AE Power: OFF")
  end
  sleep(.1) -- remove this and see if it works
end
end
Just tested, no luck. :(/> I am trying to figure out what I have enabled that'd be constantly clearing/overwriting my monitor code, but I can't seem to find it anywhere. >.> The other thread doesn't even touch the monitor, it is just supposed to handle sending/receiving to server.
BigSHinyToys #4
Posted 02 June 2013 - 10:42 PM
Do you have the correct computer ID. first argument of a rednet.send is the receiver ID not a frequency
you use computer ID 1 from what I can see in the code
Noiro #5
Posted 02 June 2013 - 10:52 PM
It is the correct ID. I can send messages back and forth between computers. Monitor just won't display. :P/>
BigSHinyToys #6
Posted 02 June 2013 - 10:53 PM
I have made a few modifications and it works now broadcasting to all systems is not that secure but it works
http://pastebin.com/KA0GTDHk
Noiro #7
Posted 02 June 2013 - 11:47 PM
*facepalms*
Yup, that fixed it. setCursorPos was all I was forgetting. Gah, thank you very much.