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

Monitor troubles

Started by SethShadowrider, 22 June 2012 - 05:08 AM
SethShadowrider #1
Posted 22 June 2012 - 07:08 AM
I am trying to make a weapons system that engages when a button is pressed. It writes its actions on a monitor, but when I give it redstone it fails trying to write to the monitor. Help would be appreciated. My code:

cake = pie
while true do
sleep(.5)
a = rs.getInput("back")
if a == true then
local mon = peripheral.wrap("right")
mon.write("Engaging weapons...")
sleep(2)
rs.setOutput("front", true)
mon.clear()
mon.write("Engaged.")
sleep(2)
mon.clear()
os.reboot()
end
end
Any tips for making code more efficient also appreciated.
OmegaVest #2
Posted 22 June 2012 - 02:42 PM
Is this part of a larger program? Does the terminal control something else?

If not, you might think about using os.pullEvent() and check to see if redstone comes in from the back. Also, check for a monitor in-code. Sometimes the program won't work unless it knows it is there. Darn you Schrodinger Complex!!!TM If that fails, just use term.redirect(mon) as you really are not using the on-board screen at all.

There ya go, some thoughts.
SethShadowrider #3
Posted 22 June 2012 - 06:15 PM
Might try the term.redirect(mon) but i'm not sure what you mean about checking for a monitor in-code…I know its receiving redstone input but the thing it the line about writing to the monitor doesn't work…
MysticT #4
Posted 22 June 2012 - 06:21 PM
He means to check if the monitor is present:

local mon
if peripheral.isPresent("<side>") and peripheral.getType("<side>") == "monitor" then
  mon = peripheral.wrap("<side>")
else
  print("No monitor found")
end
-- or
local mon = peripheral.wrap("<side>")
if not mon then
  print("No monitor found")
end
The first check is better, since you ensure that the peripheral is a monitor.
OmegaVest #5
Posted 22 June 2012 - 06:36 PM
Heh, yeah. Sorry about my horrific writing this morning MysticT, I apparently don't do very well without caffeine.

But yeah, check to see if there is a monitor. Again. Schrodinger Complex. I don't know why, but every once in a while, a computer (RL), will get a wild hair in its processor and not see something until you tell it to see that thing. Or maybe it's me.