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

OpenPeripheral Help

Started by jtgriff, 25 March 2014 - 07:19 PM
jtgriff #1
Posted 25 March 2014 - 08:19 PM
So I wrote this program to monitor my Resonant energy cell to see how much power I am drawing. The code that is below draws that bars and everything but doesn't show power. It also has an error saying that the parameter"slot" is missing.

The code:

local bridge = peripheral.wrap("right")
local net = peripheral.wrap("left")

bridge.clear()

local width = 200

local storageUnits = {
{
["id"] = "cofh_thermalexpansion_energycell_0",
["name"] = "Cell 1"
},
{
["id"] = "cofh_thermalexpansion_energycell_1",
["name"] = "Cell 2"
}
}

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
for i=#storageUnits,1,-1 do
storageUnit = storageUnits
if net.isPresentRemote(storageUnit["id"]) then
capacity = net.callRemote(storageUnit["id"], "getMaxEnergyStored")– this is where the error saying parameter "slot" is mssing
amount = net.callRemote(storageUnit["id"], "getEnergyStored")
storageUnit["bar"].setWidth(width / capacity * amount)
else
storageUnit["bar"].delete()
storageUnit["bg"].delete()
storageUnit["label"].delete()
table.remove(storageUnits, i)
end
end
sleep(0.5)
end

Please help
Edited on 25 March 2014 - 08:38 PM
Cranium #2
Posted 25 March 2014 - 08:35 PM
Moved to Ask A Pro. In the future, please make sure you post questions and other topics in the correct section.
CometWolf #3
Posted 25 March 2014 - 09:01 PM
Preferably in the correct format aswell
http://www.computercraft.info/forums2/index.php?/topic/14531-read-this-post-before-asking-questions/

Since you're getting an error the program obviously won't behave like you expect… The error would be a lot easier for us to point out of you include the whole message.
jtgriff #4
Posted 26 March 2014 - 02:44 AM
The error is in line 33 or so. it might throw another error also in line 34.
I wrote the error right next to the line
The code:

local bridge = peripheral.wrap("right")
local net = peripheral.wrap("left")

bridge.clear()

local width = 200

local storageUnits = {
{
["id"] = "cofh_thermalexpansion_energycell_0",
["name"] = "Cell 1"
},
{
["id"] = "cofh_thermalexpansion_energycell_1",
["name"] = "Cell 2"
}
}

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
for i=#storageUnits,1,-1 do
storageUnit = storageUnits
if net.isPresentRemote(storageUnit["id"]) then
capacity = net.callRemote(storageUnit["id"], "getMaxEnergyStored")– this is where the error saying parameter "slot" is mssing
amount = net.callRemote(storageUnit["id"], "getEnergyStored")
storageUnit["bar"].setWidth(width / capacity * amount)
else
storageUnit["bar"].delete()
storageUnit["bg"].delete()
storageUnit["label"].delete()
table.remove(storageUnits, i)
end
end
sleep(0.5)
end


Bomb Bloke #5
Posted 26 March 2014 - 03:46 AM
The usage of commands for OpenPeripheral peripherals varies.

Per the OP thread, say you run (via the CC prompt):

openp/docs cofh_thermalexpansion_energycell_0 getMaxEnergyStored

That will, with any luck, fill you in on the parameter you're missing.
jtgriff #6
Posted 26 March 2014 - 04:18 AM
Thank you for that it tells me that the slots are directions but them I try to enter them into the program and then I get:
No such method getMaxEnergyStored(north)
But that did get me closer
sjkeegs #7
Posted 26 March 2014 - 04:23 AM
Try this:

capacity = net.callRemote(storageUnit["id"],"getMaxEnergyStored", "south")

I still haven't quite figured out when to use "north", "south", … etc..
Edited on 26 March 2014 - 03:24 AM
jtgriff #8
Posted 26 March 2014 - 05:02 AM
Thanks that worked
Magik6k #9
Posted 26 March 2014 - 10:02 AM
@sjkeegs, iirc it is side of block the 'container' is connected to(One block can have i.e 2 tanks, each one connected to specific side)