local bridge = peripheral.wrap("right") rednet.open("top") bridge.clear() width = 200 x = 0 capacity = 80000000 amount = 0 msg = "" message = "" value = 0 mfsu0e = 1 mfsu2e = 1 local storageUnits = { { ["id"] = "mfsu_0", ["name"] = "Main Energy" } } local offset = 0 for key, storageUnit in pairs(storageUnits) do pxOffset = offset * 20 storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0x000000) storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9) -- storageUnit["bar"].setZIndex(2) storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5) offset = offset + 1 end while true do local senderID, message, distance = rednet.receive() x = message:find("x") x = x+1 msg = message:sub(x) value = tonumber(string.sub(message, 1, x-2)) if msg == "mfsu_0" then do mfsu0e = value amount = mfsu0e+mfsu2e end end if msg == "mfsu_2" then do mfsu2e = value amount = mfsu2e+mfsu0e end end for i=#storageUnits,1,-1 do widht = 200 storageUnit = storageUnits[i] storageUnit["bar"].setWidth(width / capacity * amount) write("W"..tostring(widht)) write("C"..tostring(capacity)) write("A"..tostring(amount)) end end
- ComputerCraft | Programmable Computers for Minecraft
- → Scarjit's Content
Scarjit's Content
There have been 2 items by Scarjit (Search limited from 30-March 23)
#165186 OpenPeripherals Glasses attempt to index ?
Posted by Scarjit on 17 February 2014 - 04:06 PM in Ask a Pro
Have rescripted it. New working code for the server is:
#165054 OpenPeripherals Glasses attempt to index ?
Posted by Scarjit on 16 February 2014 - 11:41 AM in Ask a Pro
Hi iv wrote an little script wich should monitor some Mfsu's using OpenPeripheral + Rednet.
Server Code:
The server should decode them in to:
mfsu_0 (id of the mfsu) and 40000000 (actual energy)
Then he should save 40000000 to mfsu_0e
The last Part is for changing the bar on the glasses.
amount = mfsu_0e+mfsu_2e is because i have 2 msfu's that i want to combine.
Server Code:
m = peripheral.wrap("top") bridge = peripheral.wrap("right") rednet.open("top") mfsu_0e = 0 mfsu_2e = 0 Cy = 1 --Mikees script bridge.clear() width = 200 local storageUnits = { { ["id"] = "mfsu_Main", ["name"] = "Main Power" } } local offset = 0 for key, storageUnit in pairs(storageUnits) do pxOffset = offset * 20 storageUnit["label"] = bridge.addText(4, 4 + pxOffset, storageUnit["name"], 0x000000) storageUnit["bar"] = bridge.addBox(4, 14 + pxOffset, 0, 5, 0xCC0000, 0.9) -- storageUnit["bar"].setZIndex(2) storageUnit["bg"] = bridge.addBox(4, 14 + pxOffset, width, 5, 0x000000, 0.5) offset = offset + 1 end --Mikees script end while true do local senderID, message, distance = rednet.receive() x = message:find("x") x = x+1 msg = message:sub(x) value = string.sub(message, 1, x-2) write(msg..": "..value) if msg == mfsu_0 then do mfsu_0e = value end end if msg == mfsu_2 then do mfsu_2e = value end end storageUnit = mfsu_Main capacity = 80000000 amount = mfsu_0e+mfsu_2e barwidht = width / capacity * amount write(mfsu_0e) storageUnit["bar"].setWidth(barwidht) endClient Code:
m = peripheral.wrap("top") rednet.open("top") mfsu0 = peripheral.wrap('mfsu_0') mfsu2 = peripheral.wrap('mfsu_2') while true do -- MFSU_0 amount = mfsu0.getEUStored() rednet.broadcast(amount.."xmfsu_0") write(amount) -- MFSU_2 amount = mfsu2.getEUStored() rednet.broadcast(amount.."xmfsu_2") write(amount) -- Other Funktions os.sleep(10) term.clear() term.setCursorPos(1,1) endThe Clients sends strings like 40000000xmfsu_0
The server should decode them in to:
mfsu_0 (id of the mfsu) and 40000000 (actual energy)
Then he should save 40000000 to mfsu_0e
The last Part is for changing the bar on the glasses.
amount = mfsu_0e+mfsu_2e is because i have 2 msfu's that i want to combine.
- ComputerCraft | Programmable Computers for Minecraft
- → Scarjit's Content