Jump to content




peripheral table?


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

#1 SpencerBeige

  • Members
  • 263 posts

Posted 25 June 2015 - 11:39 PM

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 by slow-coder, 25 June 2015 - 11:41 PM.


#2 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 25 June 2015 - 11:43 PM

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


#3 SpencerBeige

  • Members
  • 263 posts

Posted 25 June 2015 - 11:47 PM

ooh ok thanks!

#4 SpencerBeige

  • Members
  • 263 posts

Posted 26 June 2015 - 12: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?

#5 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 26 June 2015 - 12: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 by Dog, 26 June 2015 - 04:57 AM.


#6 SpencerBeige

  • Members
  • 263 posts

Posted 26 June 2015 - 01:19 AM

the newest one. 1.7. whatever.

#7 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 26 June 2015 - 02: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?

#8 SpencerBeige

  • Members
  • 263 posts

Posted 26 June 2015 - 02: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

#9 Bomb Bloke

    Hobbyist Coder

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

Posted 26 June 2015 - 04:47 AM

What if you throw in something like this?:

all[i].setCursorPos(1,1)


#10 Dog

  • Members
  • 1,179 posts
  • LocationEarth orbit

Posted 26 June 2015 - 04: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 by Dog, 26 June 2015 - 04:57 AM.


#11 SpencerBeige

  • Members
  • 263 posts

Posted 26 June 2015 - 03:33 PM

ok! thanks. although i'm not sure why that should change anything...lol

#12 Bomb Bloke

    Hobbyist Coder

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

Posted 27 June 2015 - 12: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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users