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

Not Printing On Screen "MC"

Started by DusterTheFirst, 15 May 2015 - 07:09 PM
DusterTheFirst #1
Posted 15 May 2015 - 09:09 PM
local nb = peripheral.wrap('noteBlock_0')
local s = peripheral.wrap('speaker_2')
local mc = peripheral.wrap('monitor_2')
local ml = peripheral.wrap('monitor_1')
local mr = peripheral.wrap('monitor_0')
local tl = peripheral.wrap('BigReactors-Turbine_0')
local tr = peripheral.wrap('BigReactors-Turbine_1')
local cb = peripheral.wrap('chatBox_1')

s.speak("System Engaged")

mc.setBackgroundColor(colors.green)
ml.setBackgroundColor(colors.red)
ml.clear()
ml.setCursorPos(1,1)
mr.setBackgroundColor(colors.red)
mr.clear()
mr.setCursorPos(1,1)
mc.clear()
mc.setCursorPos(1,1)
tr.setActive(false)
tl.setActive(false)

while true do

mc.clear()

ml.clear()

mr.clear()

local al = rs.getInput("left")

local input = io.read()

function airlock()

mc.setTextColor(32768)

if al == true then

mc.setTextScale(3)

mc.write(al)

end

if al == false then

mc.setTextScale(3)

mc.write("Unsealed")

end

end

airlock()

if input == "restart" then

s.speak("restarting")

mc.setBackgroundColor(colors.red)

off()

sleep(5)

os.reboot()

break

end

function off()

mc.setBackgroundColor(colors.red)

mc.clear()

ml.setBackgroundColor(colors.red)

ml.clear()

mr.setBackgroundColor(colors.red)

mr.clear()

end

if input == "shutdown" then

s.speak("Shutting Down")

off()

sleep(0)

break

end

if input == "startup left" then

ml.setBackgroundColor(colors.green)

ml.clear()

tl.setActive(true)

end

if input == "startup right" then

mr.setBackgroundColor(colors.green)

mr.clear()

tr.setActive(true)

end

if input == "shutoff left" then

ml.setBackgroundColor(colors.red)

ml.clear()

tl.setActive(false)

end

if input == "shutoff right" then

mr.setBackgroundColor(colors.red)

mr.clear()

tr.setActive(false)

end

if input == "?" then

print()

print("Commands")

print()

print("?")

print("Shutdown")

print("Restart")

print("Startup Left")

print("Startup Right")

print("Shutoff Left")

print("Shutoff Right")

end

end
Edited on 15 May 2015 - 07:12 PM
HPWebcamAble #2
Posted 16 May 2015 - 02:57 AM
Ok, a few things to note:

1. Don't post giant walls of code. Even in code tags ( [.code] , Without the . )
Use Pastebin instead
I've uploaded it for you, correctly indented:
http://pastebin.com/idrqk0vg

2. Indent!

3. What is your question? The title, 'Not Printing On Screen "MC"' isn't very clear
Bomb Bloke #3
Posted 16 May 2015 - 03:44 AM
"mc" is a wrapped monitor. You might write to it on lines 37 or 42, but then you don't pause at all before the loop flies back around to line 26, which clears whatever might've been there… So good luck seeing it. :P/>
DusterTheFirst #4
Posted 16 May 2015 - 10:42 AM
sorry for not being clear this is the paste bin http://pastebin.com/cWHKPqUJ# and it is on line 32 - 44
Edited on 16 May 2015 - 08:43 AM
flaghacker #5
Posted 16 May 2015 - 11:22 AM
Your entire code is one big mess. You are defining a function inside a while loop? What are you trying to archieve there?

I recommend structuring your code like most people:
First your variables, then your functions, and at the end your main code/loop.
I also recommend giving your variables descriptive names, so the code is easier to read. "mc" isn't really descriptive, is it?

Your actual problem is hard to find because of the mess, but you're probably writing something to the monitor and then you immediately clear the monitor, like Bomb Bloke said:

"mc" is a wrapped monitor. You might write to it on lines 37 or 42, but then you don't pause at all before the loop flies back around to line 26, which clears whatever might've been there… So good luck seeing it. :P/>
Edited on 16 May 2015 - 09:24 AM
DusterTheFirst #6
Posted 16 May 2015 - 04:42 PM
–Sets Peripheral
local nb = peripheral.wrap('noteBlock_0')
local s = peripheral.wrap('speaker_2')
local mc = peripheral.wrap('monitor_2')
local ml = peripheral.wrap('monitor_1')
local mr = peripheral.wrap('monitor_0')
local tl = peripheral.wrap('BigReactors-Turbine_0')
local tr = peripheral.wrap('BigReactors-Turbine_1')
local cb = peripheral.wrap('chatBox_1')

–Says SystemEngaged
s.speak("System Engaged")

–Clears Screens and Sets Colors
mc.setBackgroundColor(colors.green)
ml.setBackgroundColor(colors.red)
ml.clear()
ml.setCursorPos(1,1)
mr.setBackgroundColor(colors.red)
mr.clear()
mr.setCursorPos(1,1)
mc.clear()
mc.setCursorPos(1,1)
–Shutsdown Turbines
tr.setActive(false)
tl.setActive(false)

–Main Loop
while true do
–Clears Screen
mc.clear()
ml.clear()
mr.clear()

–Gets External Inputs
local al = rs.getInput("left")
local input = io.read()

–Tells You If The Room Is Sealed
function airlock()
mc.setTextColor(32768)
if al == true then
mc.setTextScale(3)
mc.write(al)
end
if al == false then
mc.setTextScale(3)
mc.write("Unsealed")
end
end

–Calls Airlock
airlock()

–From Here To The {}'s Takes Inputs And Does Stuff
–Restarts Computer
if input == "restart" then
s.speak("restarting")
mc.setBackgroundColor(colors.red)
off()
sleep(5)
os.reboot()
break
end

–Declairs off Function
function off()
mc.setBackgroundColor(colors.red)
mc.clear()
ml.setBackgroundColor(colors.red)
ml.clear()
mr.setBackgroundColor(colors.red)
mr.clear()
end

–Shutsdown Program
if input == "shutdown" then
s.speak("Shutting Down")
off()
sleep(0)
break
end

–Turns On Left Reactor
if input == "startup left" then
ml.setBackgroundColor(colors.green)
ml.clear()
tl.setActive(true)
end

–Turns On Right Reactor
if input == "startup right" then
mr.setBackgroundColor(colors.green)
mr.clear()
tr.setActive(true)
end

–Turns Off Left Reactor
if input == "shutoff left" then
ml.setBackgroundColor(colors.red)
ml.clear()
tl.setActive(false)
end

–Turns Off Right Reactor
if input == "shutoff right" then
mr.setBackgroundColor(colors.red)
mr.clear()
tr.setActive(false)
end

–Tells You All Of The Commands
if input == "?" then
print()
print("Commands")
print()
print("?")
print("Shutdown")
print("Restart")
print("Startup Left")
print("Startup Right")
print("Shutoff Left")
print("Shutoff Right")
end
–{}

end




sorry i couldent use
 
it screwed it up
Edited on 16 May 2015 - 02:43 PM
flaghacker #7
Posted 16 May 2015 - 05:35 PM
What do you mean "that screwed it up"? Try uploading the code to pastebin.

And you're still defining the airLock function inside a while loop, and everything is still a mess. Did you actually change anything?
DusterTheFirst #8
Posted 17 May 2015 - 01:52 PM

--Sets Peripherals
local nb = peripheral.wrap('noteBlock_0')
local s = peripheral.wrap('speaker_2')
local mc = peripheral.wrap('monitor_2')
local ml = peripheral.wrap('monitor_1')
local mr = peripheral.wrap('monitor_0')
local tl = peripheral.wrap('BigReactors-Turbine_0')
local tr = peripheral.wrap('BigReactors-Turbine_1')
local cb = peripheral.wrap('chatBox_1')

mc.setBackgroundColor(colors.black)
ml.setBackgroundColor(colors.black)
mr.setBackgroundColor(colors.black)

--Says SystemEngaged
s.speak("System Engaged")

--Clears Screens and Sets Colors
mc.setTextColor(colors.green)
ml.setTextColor(colors.red)
ml.clear()
ml.setCursorPos(1,1)
mr.setTextColor(colors.red)
mr.clear()
mr.setCursorPos(1,1)
mc.clear()
mc.setCursorPos(1,1)
--Shutsdown Turbines
tr.setActive(false)
tl.setActive(false)

function airlock()
  mc.clear()
  mc.write("HELLO")
  mc.write(al)
end

function off()
  mc.setTextColor(colors.red)
  ml.setTextColor(colors.red)
  mr.setTextColor(colors.red)
  mc.setCursorPos(1,1)
  ml.setCursorPos(1,1)
  mr.setCursorPos(1,1)
end

--Main Loop
while true do

--Gets External Inputs
local al = rs.getInput("left")
local input = io.read()

--Calls Airlock
airlock()

--From Here To The {}'s Takes Inputs And Does Stuff
--Restarts Computer
if input == "restart" then
s.speak("restarting")
mc.setTextColor(colors.red)
off()
sleep(5)
os.reboot()
break
end

--Shutsdown Program
if input == "shutdown" then
s.speak("Shutting Down")
off()
sleep(0)
break
end

--Turns On Left Reactor
if input == "startup left" then
ml.setTextColor(colors.green)
ml.clear()
tl.setActive(true)
end

--Turns On Right Reactor
if input == "startup right" then
mr.setTextColor(colors.green)
mr.clear()
tr.setActive(true)
end

--Turns Off Left Reactor
if input == "shutoff left" then
ml.setTextColor(colors.red)
ml.clear()
tl.setActive(false)
end

--Turns Off Right Reactor
if input == "shutoff right" then
mr.setTextColor(colors.red)
mr.clear()
  tr.setActive(false)
  end

--Tells You All Of The Commands
  if input == "?" then
  print()
  print("Commands")
  print()
  print("?")
  print("Shutdown")
  print("Restart")
  print("Startup Left")
  print("Startup Right")
  print("Shutoff Left")
  print("Shutoff Right")
  end
--{}

end

it only prints on the monitors when i break the loop
Edited on 17 May 2015 - 03:03 PM
Bomb Bloke #9
Posted 18 May 2015 - 12:52 AM
No, it always printed on the monitor - you just cleared the monitors off again so quickly that it was impossible to see.
DusterTheFirst #10
Posted 19 May 2015 - 01:22 AM
so what do i change

No, it always printed on the monitor - you just cleared the monitors off again so quickly that it was impossible to see.
Bomb Bloke #11
Posted 19 May 2015 - 05:00 AM
Truth be told, I was mistaken - later edits of your script will fail to write to the monitor, due to the changed scope of your "al" variable - you can't reference a local variable before you declare it as local, which you ended up trying to do by moving the airlock() function upwards! But my original point still stands.

See, it's basically just a case of implementing a delay in between when you write to your monitor, and when you clear it off again.

io.read() provides a decent delay, so how about you call airlock() just before that, instead of just after it? That way, what it writes will be visible so long as the system is waiting for the user to type something - when they hit enter it'll be cleared off, and near-instantly re-written again (perhaps with a new value). That way the text should be visible pretty much all the time, as opposed to how you've been doing things, where it's visible pretty much none of the time.

Just for kicks, here's a quick clean-up of the code:

Spoiler
local s = peripheral.wrap('speaker_2')
local mc = peripheral.wrap('monitor_2')
local ml = peripheral.wrap('monitor_1')
local mr = peripheral.wrap('monitor_0')
local tl = peripheral.wrap('BigReactors-Turbine_0')
local tr = peripheral.wrap('BigReactors-Turbine_1')

-- These two peripherals aren't used yet?
local nb = peripheral.wrap('noteBlock_0')
local cb = peripheral.wrap('chatBox_1')

mc.setTextColor(32768)
mc.setBackgroundColor(colors.green)
mc.setTextScale(3)

tl.setActive(false)
ml.setBackgroundColor(colors.red)
ml.clear()

tr.setActive(false)
mr.setBackgroundColor(colors.red)
mr.clear()

local function off()
	mc.setBackgroundColor(colors.red)
	mc.clear()
	ml.setBackgroundColor(colors.red)
	ml.clear()
	mr.setBackgroundColor(colors.red)
	mr.clear()
end

s.speak("System Engaged")

while true do
	mc.clear()
	mc.setCursorPos(1,1)
	if rs.getInput("left") then mc.write("Sealed") else mc.write("Unsealed") end
	
	write("Enter command (? for help): ")
	local input = io.read():lower()  -- Convert the result of the read command to lowercase to make matching simpler.
	
	if input == "restart" then
		s.speak("restarting")
		off()
		sleep(5)
		os.reboot()
	elseif input == "shutdown" then
		s.speak("Shutting Down")
		off()
		sleep(0)
		break
	elseif input == "startup left" then
		ml.setBackgroundColor(colors.green)
		ml.clear()
		tl.setActive(true)
	elseif input == "startup right" then
		mr.setBackgroundColor(colors.green)
		mr.clear()
		tr.setActive(true)
	elseif input == "shutoff left" then
		ml.setBackgroundColor(colors.red)
		ml.clear()
		tl.setActive(false)
	elseif input == "shutoff right" then
		mr.setBackgroundColor(colors.red)
		mr.clear()
		tr.setActive(false)
	elseif input == "?" then
		print()
		print("Commands")
		print()
		print("?")
		print("Shutdown")
		print("Restart")
		print("Startup Left")
		print("Startup Right")
		print("Shutoff Left")
		print("Shutoff Right")
	end
end
DusterTheFirst #12
Posted 19 May 2015 - 11:32 AM
Truth be told, I was mistaken - later edits of your script will fail to write to the monitor, due to the changed scope of your "al" variable - you can't reference a local variable before you declare it as local, which you ended up trying to do by moving the airlock() function upwards! But my original point still stands.

See, it's basically just a case of implementing a delay in between when you write to your monitor, and when you clear it off again.

io.read() provides a decent delay, so how about you call airlock() just before that, instead of just after it? That way, what it writes will be visible so long as the system is waiting for the user to type something - when they hit enter it'll be cleared off, and near-instantly re-written again (perhaps with a new value). That way the text should be visible pretty much all the time, as opposed to how you've been doing things, where it's visible pretty much none of the time.

Just for kicks, here's a quick clean-up of the code:

Spoiler
local s = peripheral.wrap('speaker_2')
local mc = peripheral.wrap('monitor_2')
local ml = peripheral.wrap('monitor_1')
local mr = peripheral.wrap('monitor_0')
local tl = peripheral.wrap('BigReactors-Turbine_0')
local tr = peripheral.wrap('BigReactors-Turbine_1')

-- These two peripherals aren't used yet?
local nb = peripheral.wrap('noteBlock_0')
local cb = peripheral.wrap('chatBox_1')

mc.setTextColor(32768)
mc.setBackgroundColor(colors.green)
mc.setTextScale(3)

tl.setActive(false)
ml.setBackgroundColor(colors.red)
ml.clear()

tr.setActive(false)
mr.setBackgroundColor(colors.red)
mr.clear()

local function off()
	mc.setBackgroundColor(colors.red)
	mc.clear()
	ml.setBackgroundColor(colors.red)
	ml.clear()
	mr.setBackgroundColor(colors.red)
	mr.clear()
end

s.speak("System Engaged")

while true do
	mc.clear()
	mc.setCursorPos(1,1)
	if rs.getInput("left") then mc.write("Sealed") else mc.write("Unsealed") end
	
	write("Enter command (? for help): ")
	local input = io.read():lower()  -- Convert the result of the read command to lowercase to make matching simpler.
	
	if input == "restart" then
		s.speak("restarting")
		off()
		sleep(5)
		os.reboot()
	elseif input == "shutdown" then
		s.speak("Shutting Down")
		off()
		sleep(0)
		break
	elseif input == "startup left" then
		ml.setBackgroundColor(colors.green)
		ml.clear()
		tl.setActive(true)
	elseif input == "startup right" then
		mr.setBackgroundColor(colors.green)
		mr.clear()
		tr.setActive(true)
	elseif input == "shutoff left" then
		ml.setBackgroundColor(colors.red)
		ml.clear()
		tl.setActive(false)
	elseif input == "shutoff right" then
		mr.setBackgroundColor(colors.red)
		mr.clear()
		tr.setActive(false)
	elseif input == "?" then
		print()
		print("Commands")
		print()
		print("?")
		print("Shutdown")
		print("Restart")
		print("Startup Left")
		print("Startup Right")
		print("Shutoff Left")
		print("Shutoff Right")
	end
end

thank you so much
DusterTheFirst #13
Posted 20 May 2015 - 08:41 PM
Can You Make A Pastebin @Bomb Bloke

Can You Make A Pastebin
flaghacker #14
Posted 20 May 2015 - 08:58 PM
Can You Make A Pastebin @Bomb Bloke

Can You Make A Pastebin

Make it yourself… http://pastebin.com/
DusterTheFirst #15
Posted 20 May 2015 - 11:36 PM
ok…
DusterTheFirst #16
Posted 22 May 2015 - 12:49 AM
http://pastebin.com/hmFcwT0M
DusterTheFirst #17
Posted 23 May 2015 - 01:06 PM
THANKS TO ALL!!!