The issue I'm having is adding turbines as peripherals. I want the program to dynamically turbines based on how many turbines are connected to the computer. I encounter a problem when the turbines don't have consecutive peripheral names ie "BigReactors-Turbine_0", "BigReactors-Turbine_1", etc.
Right now I'm using the often used wrapping function
function wrapThis(thing, x)
local wrapped, i = nil, x
while wrapped == nil and i <= 100 do
wrapped = peripheral.wrap(thing.."_"..i)
i = i + 1
end
if wrapped == nil then
return nil
else
return wrapped
end
end
and I'm attempting to wrap each turbine using a for loop
for i = 0, 3 do
t[i] = wrapThis("BigReactors-Turbine", i)
end
The problem is immediate. If the turbine labels don't start by ending with a "0", and increment by 1, then the wrapThis function will wrap the same turbine multiple times.
I'm far too inexperienced with lua to come up with a neat and tidy way to do what I want. I've looked at other programs that perform similar functions to mine (when everything is perfect), but I'm just not familiar enough with lua libraries to follow what's going on in most of them.
I'm not really looking for someone to supply me with code that will do the job, more after being pointed in the right direction.
Any tips would be greatly appreciated.