Jump to content




Issue with monitors in a program


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

#1 sjjcwatkins

  • New Members
  • 1 posts

Posted 25 April 2015 - 01:23 PM

I am working on a computer system that will receive messages, then write them to a screen. When i start the program in a computer all works, except that nothing is printed onto the screen, i have tried a few different things, but it does not work, the code is as follows:
local sid = "6"
local monitor = peripheral.wrap("back")
rednet.open("top")
message = os.pullEvent("")
monitor.setCursorPos(1,1)
monitor.setTextScale(1)
while true do
event, id, text = os.pullEvent()
if id == "sid" then
  if text == "clear" then
   if event == "rednet_message" then
	if text == "clear" then
	 monitor.clear()
	 else
	 monitor.write(message)
	end
   end
  end
end
end


#2 Square789

  • Members
  • 39 posts
  • LocationUniverse:C:/MilkyWay/Sol/Earth/Europe/Germany

Posted 25 April 2015 - 07:27 PM

You are checking "sid", which is the sring "sid" on line 9.
Take away the " s and it should work. Maybe it's also better when you remove "" out of the os.pullEvent("")
on line 4.

#3 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 25 April 2015 - 08:24 PM

os.pullEvent("") is going to yield (aka wait) until it gets the event "". Which obviously won't happen, given that no event does that. (Why are you pulling an event there, anyway?)

Since your script never advances paste line 4, I'd expect it to do nothing.

In addition, id will never equal "sid", assuming you are using the rednet_message event. It will also never equal "6". It might equal 6 (as in the number, not the string) at some point.



#4 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 25 April 2015 - 09:11 PM

This should do what you are looking for:

local id = 6  --# The id of the computer sending the messages
local m = peripheral.wrap("back") --# Wrap the monitor
rednet.open("top") --# Tell the rednet API where the modem is

m.setTextScale(1)
m.setTextColor(colors.white) --# Color of the monitor text
m.setBackgroundColor(colors.black) --# Color of the monitor background
m.clear() --# Make sure the monitor is cleared to start with
m.setCursorPos(1,1)

while true do
  local event,id,msg = os.pullEvent("rednet_message") --# wait for ONLY rednet messages

  if id == 6 then --# We only care about messages from the id we specify
    if msg == "clear" then
      --# Clear the monitor
      m.clear() 
      m.setCursorPos(1,1)
    else
      --# Print the message
      m.write(message)
      --# Go to the next line
      local x,y = m.getCursorPos()
      m.setCursorPos(1,y+1)
    end
  end
end

Note that it will print the messages it receives, one per line.
If you only want to show the last message, the code would need a little bit of modification





3 user(s) are reading this topic

0 members, 3 guests, 0 anonymous users