better component names and finding
This commit is contained in:
parent
0bdee9c64a
commit
f1676e251e
|
@ -21,7 +21,7 @@ dofile('inputClient.lua')
|
|||
local convert_joules = set_converter(options)
|
||||
|
||||
-- initialize components
|
||||
wait_for_components(options, system, 'inductionPort')
|
||||
wait_for_components(options, system, 'inductionPort', 'Induction Matrix')
|
||||
|
||||
|
||||
-- generate induction matrix values
|
||||
|
@ -91,7 +91,7 @@ function main()
|
|||
event_listener()
|
||||
end
|
||||
-- rescan components
|
||||
wait_for_components(options, system, 'inductionPort')
|
||||
wait_for_components(options, system, 'inductionPort', 'Induction Matrix')
|
||||
end
|
||||
end
|
||||
main()
|
||||
|
|
|
@ -43,11 +43,20 @@ function format_percent(options, number)
|
|||
return string.format('%.2f', number * 100) .. ' % ' .. string.rep(' ', #options.unit)
|
||||
end
|
||||
|
||||
function find_peripheral_component(name)
|
||||
for _, side in pairs(peripheral.getNames()) do
|
||||
if peripheral.getType(side) == name then
|
||||
return peripheral.wrap(side)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- scan for system components
|
||||
function scan_components(name)
|
||||
-- try finding with peripherals
|
||||
local component = peripheral.find(name)
|
||||
local modem = peripheral.find('modem')
|
||||
local component = find_peripheral_component(name)
|
||||
local modem = find_peripheral_component('modem')
|
||||
|
||||
-- check if components were found
|
||||
local found_component = not component
|
||||
|
@ -78,7 +87,7 @@ function split_string(text, delimiter)
|
|||
end
|
||||
|
||||
-- initialize ender modem
|
||||
function init_modem(options, system)
|
||||
function init_modem(options, system, name)
|
||||
system.channel = nil
|
||||
-- open initializer port
|
||||
system.modem.open(1)
|
||||
|
@ -89,7 +98,7 @@ function init_modem(options, system)
|
|||
local channel = math.random(2, 1 + options.channels)
|
||||
-- open reply channel
|
||||
system.modem.open(channel)
|
||||
system.modem.transmit(1, channel, 'matrix')
|
||||
system.modem.transmit(1, channel, name)
|
||||
|
||||
term.setCursorPos(1, 6)
|
||||
print('\nTry #' .. count)
|
||||
|
@ -128,7 +137,7 @@ function init_modem(options, system)
|
|||
end
|
||||
|
||||
-- scan for components and retry on fail
|
||||
function wait_for_components(options, system, component)
|
||||
function wait_for_components(options, system, component, name)
|
||||
system.timeout = false
|
||||
local count = 1
|
||||
-- fixed print out
|
||||
|
@ -151,7 +160,7 @@ function wait_for_components(options, system, component)
|
|||
-- set system components
|
||||
system.main = components.main
|
||||
system.modem = components.modem
|
||||
init_modem(options, system)
|
||||
init_modem(options, system, name)
|
||||
print('\nSuccess!')
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user