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

Config API

Started by Noobular, 30 March 2015 - 06:53 PM
Noobular #1
Posted 30 March 2015 - 08:57 PM
Is there anyway i can have a simple config that will worked across multiple programs?

i tried to make one extremely simple

function SetConfig()
r = peripheral.wrap("BigReactors-Reactor_0")   -- Reactor Position
m = peripheral.wrap("left")   -- Management Monitor
m2 = peripheral.wrap("monitor_0")  -- Controller Monitor
end

just setting these across all 4 programs connected, since its a pain in the arse to go across all of them and set them constantly.

after setconfig is used on the other programs it doesn't actually wrap anything it just gives me an error since it doesn't exist.

Edit: r and m2 do actually work fine on the other programs but for what ever reason theres a problem with m ill test somethings.
Noobular #2
Posted 30 March 2015 - 09:03 PM
Edit2: nevermind i'm stupid and never restarted the other programs they don't work either.
Blueberrys #3
Posted 30 March 2015 - 09:05 PM
API code:

local r = peripheral.wrap("BigReactors-Reactor_0")
function GetR()
	return r
end

To use it:

os.loadAPI("api_name")
print(api_name.GetR())

OR

API code:

r = peripheral.wrap("BigReactors-Reactor_0")

To use it:

os.loadAPI("api_name")
print(api_name.r)


Reference: Making an API
Edited on 30 March 2015 - 07:08 PM
Noobular #4
Posted 30 March 2015 - 09:16 PM
Actually it was as easy as

API:

ManageMon = "monitor_1"
Reactor = "right"
Controller = "monitor_0"

USAGE OF API:

program 1
local m = peripheral.wrap(config.ManageMon) -- Monitor for Management (5 long 3 wide)
local r = peripheral.wrap(config.Reactor) -- Big Reactors, Reactor
program 2
local m = peripheral.wrap(config.Controller) -- Monitor for Controls
local r = peripheral.wrap(config.Reactor)    -- Reactor
program 3
local r = peripheral.wrap(config.Reactor) -- Reactor