24 posts
Posted 02 September 2017 - 09:33 PM
I am trying to make a moving sign with 2 monitors connected via wire is there a way I can get this to display on both monitors and have it move using the wired modem and cables? here is my code so far. The sign does not move though… I have been scratching my head all day trying to get it to move
local pos = 18
local monitors = {
peripheral.wrap( "monitor_0" ),
peripheral.wrap( "monitor_1" ),
}
local function clear()
for _,mon in pairs( monitors ) do
mon.clear()
end
end
local function write( ... )
for _,mon in pairs( monitors ) do
mon.setBackgroundColor(32768)
mon.setTextColor(colors.white)
mon.setTextScale(5)
end
end
while true do
if pos==-22 then
pos = 10
end
local function clear()
for _,mon in pairs( monitors ) do
mon.clear()
end
end
local function write( ... )
for _,mon in pairs( monitors ) do
mon.setCursorPos(pos,1)
mon.write("Outraged DataCenters .INC")
pos = pos-1
end
end
os.sleep(0.15)
end
Edited on 02 September 2017 - 07:34 PM
3057 posts
Location
United States of America
Posted 02 September 2017 - 10:56 PM
I'm going to go through your code and clean it up a bit, adding comments where I do so. Note: I didn't actually
test this code. It's just a cleaned-up version of what I think you were trying to accomplish.
Spoiler
local pos = 18
local monitors = {
peripheral.wrap( "monitor_0" ),
peripheral.wrap( "monitor_1" ),
}
local function clear()
for _,mon in pairs( monitors ) do
mon.clear()
end
end
--# I've renamed this function so it doesn't share a name with the built-in write() function.
local function monWrite( text ) --# you don't need endless parameters, just one, so I'll name it here.
for _,mon in pairs( monitors ) do
--# fix indentation issues
mon.setBackgroundColor(32768)
mon.setTextColor(colors.white)
mon.setTextScale(5)
--# this bit was taken from the function redefining that was previously inside the loop
mon.setCursorPos(pos,1)
--# add a line to actually accomplish the writing to the monitor bit
mon.write( text )
end
end
--# everything inside this loop needed indented 1 level
while true do
if pos==-22 then
pos = 10
end
--# I rather doubt you wanted to re-define your clear() function,
--# you probably wanted to call it instead.
clear()
--# Ditto for the (formerly known as write) monWrite function.
monWrite("Outraged DataCenters .INC")
pos = pos-1
os.sleep(0.15)
end
Edited on 02 September 2017 - 08:58 PM
24 posts
Posted 02 September 2017 - 11:49 PM
I'm going to go through your code and clean it up a bit, adding comments where I do so. Note: I didn't actually
test this code. It's just a cleaned-up version of what I think you were trying to accomplish.
Spoiler
local pos = 18
local monitors = {
peripheral.wrap( "monitor_0" ),
peripheral.wrap( "monitor_1" ),
}
local function clear()
for _,mon in pairs( monitors ) do
mon.clear()
end
end
--# I've renamed this function so it doesn't share a name with the built-in write() function.
local function monWrite( text ) --# you don't need endless parameters, just one, so I'll name it here.
for _,mon in pairs( monitors ) do
--# fix indentation issues
mon.setBackgroundColor(32768)
mon.setTextColor(colors.white)
mon.setTextScale(5)
--# this bit was taken from the function redefining that was previously inside the loop
mon.setCursorPos(pos,1)
--# add a line to actually accomplish the writing to the monitor bit
mon.write( text )
end
end
--# everything inside this loop needed indented 1 level
while true do
if pos==-22 then
pos = 10
end
--# I rather doubt you wanted to re-define your clear() function,
--# you probably wanted to call it instead.
clear()
--# Ditto for the (formerly known as write) monWrite function.
monWrite("Outraged DataCenters .INC")
pos = pos-1
os.sleep(0.15)
end
Thanks so much. I have so stumped also is there a way to display a second message after the first one without an issue or? I am just wondering also the code works perfectly fine!
Edited on 02 September 2017 - 09:53 PM
3057 posts
Location
United States of America
Posted 03 September 2017 - 03:25 AM
Sure, just add it to the end of the "Outrage (…) .INC" string and update the position comparison to reflect the new length.