Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This is written for OpenComputers
- -- Returns a table of method proxies for each component of type
- -- Type can be abbreviated, since component.proxy supports that
- -- If type is empty, it iterates over ALL components
- local component = require("component")
- local function findComps(type)
- local comps = {}
- local compNames = {}
- compList = component.list(type)
- for cAddress,cType in compList do
- -- Insert proxy methods table into comps table
- table.insert(comps, component.proxy(cAddress))
- -- Insert component type into compNames table
- table.insert(compNames, cType)
- end
- return comps, compNames
- end
- -- Usage example:
- local cellTable = findComps("tile_thermalexpansion_cell_resonant_name")
- local firstCellEnergy = cellTable[1].getMaxEnergyStored()
- print(firstCellEnergy) -- Prints "50000000", since resonant energy cells have a max storage of 50,000,000
- -- Abbreviated usage:
- print(findComps("tile_thermalexpansion_cell_resonant_name")[1].getMaxEnergyStored())
- -- Print type of each component
- local comps, compNames = findComps()
- for i=1, #compNames do
- print(compNames[i])
- end
- -- Print methods available for each component
- local comps, compNames = findComps()
- for i=1, #comps do -- Iterate components
- for k,v in pairs(comps[i]) do -- Iterate methods
- print(k) -- Print method name
- end
- end
- -- Print max value for each cell it finds
- -- Note that this abbreviates the type, so it finds all energy cells of all types (leadstone, hardened, redstone, resonant, etc)
- local cellTable = findComps("tile_thermalexpansion_cell")
- for i=1, #cellTable do
- print(cellTable[i].getMaxEnergyStored())
- end
- -- Print current energy percent for each cell it finds
- local cellTable = findComps("tile_thermalexpansion_cell")
- for i=1, #cellTable do
- local prcnt = math.floor(cellTable[i].getEnergyStored()/cellTable[i].getMaxEnergyStored()*100)
- print(prcnt.."%")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement