This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
use a peripheral to wrap a peripheral
Started by EveryOS, 29 April 2016 - 09:06 PMPosted 29 April 2016 - 11:06 PM
Apperently the peripheral api doesn't get updated when redirecting to a new object. Anything I can do about this? I want to wrap multiple peripherals.
Posted 29 April 2016 - 11:07 PM
What do you mean by 'redirecting'? The peripheral API doesn't redirect, and neither do peripherals.
Posted 29 April 2016 - 11:15 PM
You can always warp more than one peripheral, It's more than likely your own implementation that's screwing up.
Posted 29 April 2016 - 11:26 PM
My code
side = 'left'
local boleen =true
while boleen do
local peri = peripheral.wrap(side)
if peri then
term.redirect(peri)
term.setBackgroundColor(colors.blue)
term.clear()
else boleen = false
end
end
Something like thatPosted 29 April 2016 - 11:32 PM
Yeah, your code will have to handle that. Luckily, there's an event for that!.
Edited on 29 April 2016 - 09:32 PM
Posted 29 April 2016 - 11:52 PM
It seems to me what he wants to happen is have a chain of computers or monitors or whatever in a line with each successive to the left and he assume that term.redirect would basically make everything act as if it's on the peripheral itself, such that any peripheral commands are on the wrapped computer.
Say we have a chain of computer a,b,c in that order, next to each other. If computer c executes this code, what I'm assuming he wants to happen, is turn the screens on both b and a, blue.
Say we have a chain of computer a,b,c in that order, next to each other. If computer c executes this code, what I'm assuming he wants to happen, is turn the screens on both b and a, blue.
Posted 30 April 2016 - 12:00 AM
I can't really use quotes on this device, but yes. The problem, I think, is that only the terminal updates. I'm planning on using this for a bigMon API
I can't really use quotes on this device, but yes. The problem, I think, is that only the terminal updates. I'm planning on using this for a bigMon API
I can't really use quotes on this device, but yes. The problem, I think, is that only the terminal updates. I'm planning on using this for a bigMon API
Posted 30 April 2016 - 12:03 AM
Yeah you'd have to create your own program to do so, the peripheral api does nothing like you're wanting, no in built system does what you want. The peripheral api allows you to interact in predefined ways, with a monitor you can draw to it, with a computer you can turn it on, with a reactor you can get it's values, but you cannot act as if you are the block itself. The code you write on one machine only runs on that one machine. If you want to cause a master computer to update things on many computers/monitors, you need to program it specifically, draw what you want on the monitors, and make a program for each computer that allows you to tell it what to do.
Posted 30 April 2016 - 12:09 AM
):
Posted 30 April 2016 - 12:13 AM
I would take a look at the rednet api and modem api and choose which you'd like to do for communication between computers.
Rednet
Modem
All you really have to do is set up a set of either keywords that you check for on the receiving computer and allow it to run certain code or try to loadstring() the message you get.
Also, instead of having me try to take a guess on the purpose of what you're trying, perhaps you could step away from the code showing and just in plain words say what you're attempting to achieve next time. Such as what I did, allowing a computer to run code if it was another computer. Not possible of course without creating your own program or using anothers but still. Easier to understand and give help instead of assuming a function does exactly what you want.
Rednet
Modem
All you really have to do is set up a set of either keywords that you check for on the receiving computer and allow it to run certain code or try to loadstring() the message you get.
Also, instead of having me try to take a guess on the purpose of what you're trying, perhaps you could step away from the code showing and just in plain words say what you're attempting to achieve next time. Such as what I did, allowing a computer to run code if it was another computer. Not possible of course without creating your own program or using anothers but still. Easier to understand and give help instead of assuming a function does exactly what you want.
Edited on 29 April 2016 - 10:17 PM
Posted 30 April 2016 - 12:49 AM
If you want a big monitor thing, I made one for recent versions (ei those with term.blit).
Posted 30 April 2016 - 01:36 AM
You want to wrap a bunch of monitors as peripherals? You hook them all up using wired modems, and you wrap them all.
Each peripheral has a number of actions it is able to perform. You can access these via peripheral.call(); eg:
All peripheral.wrap() does is create a table, and dump one function pointer in it for each action the peripheral can handle. This allows for easy calling later:
peripheral.find() allows you to wrap multiple devices in one go:
But all wrapping does is get you that "easy access" table. It doesn't "change" anything.
The "terminal" is the computer's default output device. Most output commands - eg print, write, the whole paintutils API, and so on - use the default terminal. You can change the default terminal using term.redirect(), but all this does is change where the output from those commands goes. It does not change "the location of the computer itself", and you should also note that you can only have one default terminal at a time.
"Terminal objects" basically consist of tables that hold function pointers named after (nearly) all the functions in the term API. You make a table with those functions in it and voilà, you've got something you can pass to term.redirect().
The table returned when you wrap a monitor "happens" to contain these functions, and so is a valid terminal object. Not all peripherals are monitors, though! Wrapping a monitor gets you a terminal object because of the nature of monitors, not because of anything specific to the peripheral API. If you wrap eg a printer you'll get an entirely different set of functions!
You can create your own term objects, too - Stitch (linked above) is one example, whereby multiple monitors are wrapped, and a term object is generated (by manually defining the relevant functions and sticking them in a table) which allows you to treat them all as one big display.
A similar (and simpler) concept can be seen here - a term object is rigged up which draws everything passed to it to all attached monitors, creating a mirroring effect.
The window API is yet another example, whereby the "window" term object really just draws to whatever term object you specify as the "parent" when creating the window - but it caches everything you draw through it, so you can redraw it later if need be.
Each peripheral has a number of actions it is able to perform. You can access these via peripheral.call(); eg:
peripheral.call("someMonitor", "clear")
All peripheral.wrap() does is create a table, and dump one function pointer in it for each action the peripheral can handle. This allows for easy calling later:
local mon = peripheral.wrap("someMonitor")
mon.clear()
peripheral.find() allows you to wrap multiple devices in one go:
local mons = {peripheral.find("monitor")}
for i = 1, #mons do
mons[i].clear()
end
But all wrapping does is get you that "easy access" table. It doesn't "change" anything.
The "terminal" is the computer's default output device. Most output commands - eg print, write, the whole paintutils API, and so on - use the default terminal. You can change the default terminal using term.redirect(), but all this does is change where the output from those commands goes. It does not change "the location of the computer itself", and you should also note that you can only have one default terminal at a time.
"Terminal objects" basically consist of tables that hold function pointers named after (nearly) all the functions in the term API. You make a table with those functions in it and voilà, you've got something you can pass to term.redirect().
The table returned when you wrap a monitor "happens" to contain these functions, and so is a valid terminal object. Not all peripherals are monitors, though! Wrapping a monitor gets you a terminal object because of the nature of monitors, not because of anything specific to the peripheral API. If you wrap eg a printer you'll get an entirely different set of functions!
You can create your own term objects, too - Stitch (linked above) is one example, whereby multiple monitors are wrapped, and a term object is generated (by manually defining the relevant functions and sticking them in a table) which allows you to treat them all as one big display.
A similar (and simpler) concept can be seen here - a term object is rigged up which draws everything passed to it to all attached monitors, creating a mirroring effect.
The window API is yet another example, whereby the "window" term object really just draws to whatever term object you specify as the "parent" when creating the window - but it caches everything you draw through it, so you can redraw it later if need be.
Edited on 29 April 2016 - 11:38 PM