CLNinja, on 24 March 2018 - 02:36 PM, said:
This sort of thing has been done time and time again. I really don't think we need another one.
You could say that about many CC programs though.
Looks at the Operating Systems section.
MisterMeister32: this is actually pretty decent code for a first program, good job! One thing I'd recommend is prefixing all your variable definitions with "local". It's a rather trivial change, but means values are specific to a given function, rather than leaked across programs. So you'd change your code to look something like:
local function open() --# Note the "local function" instead
local p = peripheral.getNames() --# Again, note the use of local when declaring the variable.
local modem = nil
for i = 1, #p do --seaching for modems
if peripheral.getType(p[i]) == "modem" then
modem = p[i] --# As we're setting an existing variable, we don't need it here.
end
end
There's also a neat little trick you can do with
peripheral.find in order to open all modems. Instead of looping through each modem and opening it, you can do:
peripheral.find("modem", rednet.open)