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

peripheral table?

Started by SpencerBeige, 25 June 2015 - 10:39 PM
SpencerBeige #1
Posted 26 June 2015 - 12:39 AM
i have a bunch of monitors setup. lets just say i have top, bottom, left, right, back, and front.

i wanted to be able to control multiple of them at once, so i could compact the code. my original idea was this:


peri = {top, bottom}
peri.clear()

well, this didn't work. so i'm wondering how to control multiple peripherals at once.
and i know i could just use the same commands for bottom and top, but the gets extremely boring.
Edited on 25 June 2015 - 10:41 PM
Dog #2
Posted 26 June 2015 - 12:43 AM
Your code won't work because you haven't wrapped 't' to any peripheral. Then it would just do the single, wrapped peripheral. What you want to do is build a table, then iterate through the table with the commands you wish to execute. For example, in CC 1.6 and later you can do this…

local monitors = { peripheral.find("monitor") }
for i = 1, #monitors do
  monitors[i].setBackgroundColor(colors.black)
  monitors[i].clear()
end
SpencerBeige #3
Posted 26 June 2015 - 12:47 AM
ooh ok thanks!
SpencerBeige #4
Posted 26 June 2015 - 01:09 AM
well now i have an issue with the monitors.


front = peripheral.wrap("monitor_0")
left = peripheral.wrap("monitor_1")
right = peripheral.wrap("monitor_2")
bottom = peripheral.wrap("monitor_3")
top = peripheral.wrap("monitor_4")
back = peripheral.wrap("monitor_5")
all = {front, left, right, bottom, top, back}

for i = 1, #all do
all[i].setTextColor(colors.white)
all[i].setBackgroundColor(colors.black)
all[i].clear()
all[i].write("hello world")
end

i run that, but no text appears. i also tried setting the background colour, then clearing the screen, and sure enough, that worked. do you know what the problem is?
Dog #5
Posted 26 June 2015 - 01:31 AM
What version of ComputerCraft are you using?

EDIT: edited wrong post - and while I was here I removed an incorrect statement on my part
Edited on 26 June 2015 - 03:57 AM
SpencerBeige #6
Posted 26 June 2015 - 02:19 AM
the newest one. 1.7. whatever.
Dog #7
Posted 26 June 2015 - 03:24 AM
Then I'd recommend using peripheral.find() as I did in my example. Is there some reason you need to manually wrap each monitor?
SpencerBeige #8
Posted 26 June 2015 - 03:38 AM
yes. i would like to be able to control which one i use, like i can use top and bottom without having to use all of them. when i just changed the background colour and cleared the screen, it worked. when i print text, it doesn't
Bomb Bloke #9
Posted 26 June 2015 - 05:47 AM
What if you throw in something like this?:

all[i].setCursorPos(1,1)
Dog #10
Posted 26 June 2015 - 05:55 AM
OK, I tested your script and it worked with one change. Add this…

all[i].setCursorPos(1, 1)

to your loop and it should work.

EDIT: :ph34r:/> 'd
Edited on 26 June 2015 - 03:57 AM
SpencerBeige #11
Posted 26 June 2015 - 04:33 PM
ok! thanks. although i'm not sure why that should change anything…lol
Bomb Bloke #12
Posted 27 June 2015 - 01:29 AM
Every time you write something to a monitor, the cursor moves - and it's allowed to move off the edge of the display. Clearing the display does not move the cursor, so if you want to be sure the text to be written where you can see it, it's up to you to specify where you want it.

When you say you're on the "newest" version of ComputerCraft, if you mean the latest beta (1.74pr37), then be aware that it contains a bug which may prevent you from seeing text written to monitors (even if the cursor is correctly positioned). Dan reckons he's fixed it, so presumably it'll work in the next build he posts. The latest stable release, 1.73, doesn't have this problem.