Posted 22 April 2014 - 02:54 PM
Hello guys, i'm back with one more problem that i can not find a solution to (Searched the webs forever)
It's about wireless modem and the use of Rednet/pullEVent
So i've set up a test system where i'm trying to get this to work:
1 capacitor bank with energy in it. - 1 computer(X) besides it with wirless modem - 1 computer(Y) with wireless modem and a monitor.
So computer(X) takes the data from the bank, then sends it to computer(Y) which then sends the data to the monitor.
Now what i can't figure out, is how to cut the diffrent variables out when on the second computer, since it all comes as text.
So i've set up the "layout" of the data on computer(X) and then just using computer(Y) mon.write(message) which is not very flexible. as i'd have to do all the layouting on the computer by the bank, instead of the computer in my house.
This is the code i've used:
Computer(X)
It's about wireless modem and the use of Rednet/pullEVent
So i've set up a test system where i'm trying to get this to work:
1 capacitor bank with energy in it. - 1 computer(X) besides it with wirless modem - 1 computer(Y) with wireless modem and a monitor.
So computer(X) takes the data from the bank, then sends it to computer(Y) which then sends the data to the monitor.
Now what i can't figure out, is how to cut the diffrent variables out when on the second computer, since it all comes as text.
So i've set up the "layout" of the data on computer(X) and then just using computer(Y) mon.write(message) which is not very flexible. as i'd have to do all the layouting on the computer by the bank, instead of the computer in my house.
This is the code i've used:
Computer(X)
per = peripheral.wrap("left")
local function round( num, places )
places = 10 ^ places
return math.floor((num * places) + 0.5 ) / places
end
while true do
energy = per.getEnergyStored("left")
energyMax = per.getMaxEnergyStored("left")
sleep(1)
rednet.open("right")
rednet.send(7, round(energy/1000000, 1).."M".." of "..round(energyMax/1000000, 1).."M".." = "..round(energy/energyMax*100, 1).."%")
print(round(energy/1000000, 1),"M")
end
Computer(Y)
mon = peripheral.wrap("top")
function listen()
while true do
rednet.open("right")
id,message = rednet.receive()
if id == 6 then --3 is the Id of the main pc
mon.setCursorPos(1,1)
mon.write("------Energy Bank 1------")
mon.setCursorPos(1,2)
mon.clearLine()
mon.write("Stored Energy: "..message)
end
end
end
while true do
listen()
end