Jump to content




Not Printing On Screen "MC"


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

#1 DusterTheFirst

  • Members
  • 40 posts

Posted 15 May 2015 - 08: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 by DusterTheFirst, 15 May 2015 - 08:12 PM.


#2 HPWebcamAble

  • Members
  • 933 posts
  • LocationWeb Development

Posted 16 May 2015 - 01:57 AM

Ok, a few things to note:

1. Don't post giant walls of code. Even in code tags ( [.code] [/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

#3 Bomb Bloke

    Hobbyist Coder

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

Posted 16 May 2015 - 02: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

#4 DusterTheFirst

  • Members
  • 40 posts

Posted 16 May 2015 - 09:42 AM

sorry for not being clear this is the paste bin http://pastebin.com/cWHKPqUJ# and it is on line 32 - 44

Edited by DusterTheFirst, 16 May 2015 - 09:43 AM.


#5 flaghacker

  • Members
  • 655 posts

Posted 16 May 2015 - 10: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:

View PostBomb Bloke, on 16 May 2015 - 02:44 AM, 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 by flaghacker, 16 May 2015 - 10:24 AM.


#6 DusterTheFirst

  • Members
  • 40 posts

Posted 16 May 2015 - 03: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 by DusterTheFirst, 16 May 2015 - 03:43 PM.


#7 flaghacker

  • Members
  • 655 posts

Posted 16 May 2015 - 04: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?

#8 DusterTheFirst

  • Members
  • 40 posts

Posted 17 May 2015 - 12: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 by Lyqyd, 17 May 2015 - 04:03 PM.


#9 Bomb Bloke

    Hobbyist Coder

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

Posted 17 May 2015 - 11:52 PM

No, it always printed on the monitor - you just cleared the monitors off again so quickly that it was impossible to see.

#10 DusterTheFirst

  • Members
  • 40 posts

Posted 19 May 2015 - 12:22 AM

so what do i change

View PostBomb Bloke, on 17 May 2015 - 11:52 PM, said:

No, it always printed on the monitor - you just cleared the monitors off again so quickly that it was impossible to see.


#11 Bomb Bloke

    Hobbyist Coder

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

Posted 19 May 2015 - 04: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


#12 DusterTheFirst

  • Members
  • 40 posts

Posted 19 May 2015 - 10:32 AM

View PostBomb Bloke, on 19 May 2015 - 04:00 AM, said:

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

thank you so much

#13 DusterTheFirst

  • Members
  • 40 posts

Posted 20 May 2015 - 07:41 PM

Can You Make A Pastebin @Bomb Bloke

View PostBomb Bloke, on 20 May 2015 - 07:40 PM, said:

Can You Make A Pastebin


#14 flaghacker

  • Members
  • 655 posts

Posted 20 May 2015 - 07:58 PM

View PostDusterTheFirst, on 20 May 2015 - 07:41 PM, said:

Can You Make A Pastebin @Bomb Bloke

View PostBomb Bloke, on 20 May 2015 - 07:40 PM, said:

Can You Make A Pastebin

Make it yourself... http://pastebin.com/

#15 DusterTheFirst

  • Members
  • 40 posts

Posted 20 May 2015 - 10:36 PM

ok...

#16 DusterTheFirst

  • Members
  • 40 posts

Posted 21 May 2015 - 11:49 PM

http://pastebin.com/hmFcwT0M

#17 DusterTheFirst

  • Members
  • 40 posts

Posted 23 May 2015 - 12:06 PM

THANKS TO ALL!!!





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users