Jump to content




Bit of multi-peripheral addition help.


  • You cannot reply to this topic
3 replies to this topic

#1 Inumel

  • Members
  • 120 posts

Posted 29 April 2015 - 05:15 AM

I am using some delicious peripheral wrapping code provided in another post by Lyqyd
function wrapAll(type)
  local wrapped, names = {}, {}
  for _, name in ipairs(peripheral.getNames()) do
	if peripheral.getType(name) == type then
	  table.insert(names, name)
	end
  end
  for _, fn in ipairs(peripheral.getMethods(names[1])) do
	wrapped[fn] = function(...)
	  local returns = {}
	  for i = 1, #names do
		returns[i] = peripheral.call(names[i], fn, ...)
	  end
	  return returns
	end
  end
  return wrapped
end


which I am using on IC2 batboxes, batbox = wrapAll("batbox") That works all fine and dandy,

I wrote a quick thing to get its energy,
test = batbox.getEUStored()
  for k,v in pairs(test) do
   print(v)
	end
Which outputs the energy of all 24(yes, 24 batboxes) properly. The issue is, that insane amount of info is hard to display on a monitor, so i wanted to coalesce the energy outputs of each batbox, sadly I don't know how to do so in the required for loop.



Any help is of course appreciated, credit for all above code goes to LYQYD

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 29 April 2015 - 06:50 AM

Your monitor will likely have plenty of columns, so I suppose you could use those to draw a bar chart. Calculate a percentage of how full each batbox is, and draw a line from the bottom of the screen leading up X% of the way to the top.

Either that or just print an average, I suppose. Or even just "(combined energy) / (total storage)".

#3 Inumel

  • Members
  • 120 posts

Posted 29 April 2015 - 03:26 PM

View PostBomb Bloke, on 29 April 2015 - 06:50 AM, said:

Your monitor will likely have plenty of columns, so I suppose you could use those to draw a bar chart. Calculate a percentage of how full each batbox is, and draw a line from the bottom of the screen leading up X% of the way to the top.

Either that or just print an average, I suppose. Or even just "(combined energy) / (total storage)".

It was my intention to combine all of the power and show a percentage of total power out of total capacity, but I don't know how to combine the energy readings, not with how they're presented

#4 flaghacker

  • Members
  • 655 posts

Posted 29 April 2015 - 03:34 PM

Just replace the print with something else:

totalEU = 0
test = batbox.getEUStored ()
for _, v in pairs do
  totalEU = totalEU + v
end
print (totalEU)

Edited by flaghacker, 29 April 2015 - 03:35 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users