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

assign array values

Started by DTM450, 27 May 2016 - 07:35 AM
DTM450 #1
Posted 27 May 2016 - 09:35 AM
need help with the second half of the code

its supposed to wrap the reactors as a peripheral and then set a value as on or off depending on whether or not it is active


local reactors = {}

local function reactorSearch()
  local names = peripheral.getNames()
  local n = 0
  local i, name

  for i, name in pairs(names) do
	if peripheral.getType(name) == "BigReactors-Reactor" then
	  reactors[n] = name
	  n = n + 1
	else
	  --return null
	end
  end
end

--#TODO: fix this function (wrap and state)
-- #wrap each reactor in reactors{"BigReactors-Reactor_0",etc}
-- #then determine if the reactor is active and set reactor_X to "ON" or "OFF"

local function rA1()
  for a,v in ipairs(reactors) do
  reactors[v] = peripheral.wrap(reactors[v])

  if reactors[v].getActive() == true then
	reactors[v:sub(13)] = "ON"
  else
	reactors[v:sub(13)] = "OFF"
  end

  end
end
Edited on 27 May 2016 - 07:37 AM
KingofGamesYami #2
Posted 27 May 2016 - 01:13 PM
What's the problem? It looks like it should work.
DTM450 #3
Posted 27 May 2016 - 01:21 PM
huh it must be another part of my code then

yup just tested it this works fine
Edited on 27 May 2016 - 11:21 AM