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

my code

Started by Duster, 09 April 2016 - 05:14 PM
Duster #1
Posted 09 April 2016 - 07:14 PM
is there anyway i could compact this down?

just this the other 2 launched by multi-shell are irrelevant


multishell.launch({}, "Debug", 100)
multishell.launch({}, "Input", 1)
multishell.setTitle(multishell.getCurrent(), "Keep On")
while true do
c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11 = peripheral.find("computer")
c1.turnOn()
c2.turnOn()
c3.turnOn()
c4.turnOn()
c5.turnOn()
c6.turnOn()
c7.turnOn()
c8.turnOn()
c9.turnOn()
c10.turnOn()
c11.turnOn()
sleep(1)
end
Lyqyd #2
Posted 09 April 2016 - 07:18 PM

local function on(_, comp)
  comp.turnOn()
end

while true do
  peripheral.find("computer", on)
  sleep(1)
end
Duster #3
Posted 10 April 2016 - 11:17 AM

local function on(_, comp)
  comp.turnOn()
end

while true do
  peripheral.find("computer", on)
  sleep(1)
end
the computers are not turning on…
Lupus590 #4
Posted 10 April 2016 - 02:44 PM
is the red light on for each modem?
Duster #5
Posted 10 April 2016 - 03:38 PM
yes
is the red light on for each modem?
Wergat #6
Posted 10 April 2016 - 03:44 PM
Something like this might do to shorten the while loop.
It puts all the computers it can find into a table, then runs though the table and turns all the computers on. This gets rid of all the variables you used and does not limit to 11 computers, too.

while true do
  local t = {peripheral.find("computer")}
  for i = 1,#t do
	t[i].turnOn()
  end
  sleep(1)
end

Edit: Some typing errors, coded in editor
Edited on 10 April 2016 - 01:46 PM
KingofGamesYami #7
Posted 10 April 2016 - 04:07 PM
Does the original code work when Lyqyd's does not?
Bomb Bloke #8
Posted 10 April 2016 - 11:26 PM
It does the same thing, so all other things being equal, it won't.