This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Doobliheim's profile picture

Help With Broadcasting Power Levels To Monitor

Started by Doobliheim, 23 October 2016 - 07:06 AM
Doobliheim #1
Posted 23 October 2016 - 09:06 AM
I'm playing Direwolf20 and I'm trying to get a computer to broadcast the power level of a Draconic Energy Core to a monitor in my main area of operations, which has a monitor. The mod has open OpenPeripherals which lets me use the peripheral.getEnergyStored and the peripheral.getMaxEnergyStored commands. What I want it to do is constantly run the commands (while true do?) and broadcast the reading it gets to a monitor in my base. How would I go about doing this? I'm pretty new to wireless modems so I need a bit of help getting those set up.
KingofGamesYami #2
Posted 23 October 2016 - 01:23 PM
First, you need to open rednet on both computers. To do this, find the side the wireless modems are on (eg "right") and use

rednet.open( "right" ) --# replace "right" with appropriate side

Once you have them open, you should use a rednet.receive on the receiving computer, like this:

while true do
  local id, message = rednet.receive() --# note: You may want to use a timeout
  print( message[ 1 ] )
  print( message[ 2 ] )
  --#I assume you can convert print to the appropriate display
end

On the sending computer, you should have an infinate loop, like you said, but you should also execute it only once per second.


while true do
  local currentEnergy = --# get current energy
  local maxEnergy = --#get max energy
  rednet.broadcast( {currentEnergy, maxEnergy} ) --# you can send tables over rednet
  sleep( 1 ) --# wait 1 second.  Updating more than this is really not very helpful, as there will be no significant difference in the power level
end

That will get you a pretty basic setup. Reply if you need more assistance.