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

OpenPeripheral Energy Monitoring

Started by FXgamer247, 22 August 2014 - 02:32 AM
FXgamer247 #1
Posted 22 August 2014 - 04:32 AM
I am fairly new to programming in general. But I know a good amount of lua. Even still; I can't figure out for the life of me how to get energy readings from a Mekanism energy cube. This is the code I am trying:


battery = peripheral.wrap("back")
print(battery.getMJStored("unknown")

It doesn't print anything, and if I set it to a variable it doesn't do anything, it also doesn't set it as a table. (Even if I try and print the variable/table)

The documentation says that the usage is varname.getMJStored(direction), but I have tried everything:

North
West
East
South
Front
Back
Left
Right
Up
Down
Unknown

But nothing works.

Im using Minecraft 1.6.4 ComputerCraft 1.63 and OpenPeripheralCore 0.4.1 and OpenPeripheralAddons 0.1.5

I probably made some stupid mistake, but I can't find it anywhere, since there is no longer online documentation for OpenPeripherals.
Dog #2
Posted 22 August 2014 - 06:17 AM
The directions you want to try are:
"up"
"down"
"north"
"south"
"east"
"west"

Hope that helps :)/>
theoriginalbit #3
Posted 22 August 2014 - 06:52 AM
the one Dog missed out is "unknown" the major thing to point out there is the capital first letter, it is case sensitive.
Bomb Bloke #4
Posted 22 August 2014 - 06:54 AM
Note that case sensitivity matters.

Edit: :ph34r:/>'d
Edited on 22 August 2014 - 04:55 AM
Dog #5
Posted 22 August 2014 - 08:41 AM
Well, darnit, I *did* forget to put "unknown" - thanks for catching that, Bit :)/>
FXgamer247 #6
Posted 22 August 2014 - 09:54 AM
I did try it without capitals. It just returns nothing. And if I try to print it as a table, it returns nil

UPDATE: I used this code just to check EVERY direction:


battery = peripheral.wrap("back")
dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
"front",
"back",
"left",
"right",
"top",
"bottom",
}

for side = 1, #dir do
print(battery.getMJStored(dir[side]))
end

This prints out:

0
0
0
0

0









Also, when I try "print(battery.getMaxMJStored(dir[side])", it displays "5120000" for north, west, east, south, and down, but not up.
Edited on 22 August 2014 - 08:22 AM
Dog #7
Posted 22 August 2014 - 05:22 PM
FIrst, you should always localize your variables and functions like so…

local battery = peripheral.wrap("back")
local dir = {

Next, try this code and tell me what you get…

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
"front",
"back",
"left",
"right",
"top",
"bottom",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getMJStored(dir[side]))
end

The code you were using was counting from 1 to the number of entries in the 'side' table then passing that number instead of the side.
Edited on 22 August 2014 - 04:57 PM
FXgamer247 #8
Posted 22 August 2014 - 08:09 PM
FIrst, you should always localize your variables and functions like so…

local battery = peripheral.wrap("back")
local dir = {

Next, try this code and tell me what you get…

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
"front",
"back",
"left",
"right",
"top",
"bottom",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getMJStored(dir[side]))
end

The code you were using was counting from 1 to the number of entries in the 'side' table then passing that number instead of the side.

This returns: "temp: 19: Argument direction cannot be null"

So i tried changing the print to print(dir[side]), and it print absolutely nothing.
Dog #9
Posted 22 August 2014 - 08:31 PM
This returns: "temp: 19: Argument direction cannot be null"

So i tried changing the print to print(dir[side]), and it print absolutely nothing.
If you want to see it print out the sides in the list you would use

print(side)

Which points out a mistake I made in the code I asked you to run. Please run this and tell me what the results are

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getMJStored(side))
end
FXgamer247 #10
Posted 22 August 2014 - 08:49 PM
This returns: "temp: 19: Argument direction cannot be null"

So i tried changing the print to print(dir[side]), and it print absolutely nothing.
If you want to see it print out the sides in the list you would use

print(side)

Which points out a mistake I made in the code I asked you to run. Please run this and tell me what the results are

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getMJStored(side))
end

It doesn't work. It prints out:

north: 0
west: 0
east: 0
south: 0
temp: 13: attempt to concatenate string and nil

I removed up from the table and it did the same thing for "unknown", but down still came out as 0
Edited on 22 August 2014 - 06:49 PM
Dog #11
Posted 22 August 2014 - 08:52 PM
Do you have the Energy Cube attached directly to the back of the computer (no peripheral proxy/modem)?

Is the output side of the Energy Cube the side that is attached the the computer?

What versions of MC, Mekanism, OpenPeripheral, ComputerCraft, and Forge are you using?
Edited on 22 August 2014 - 07:00 PM
FXgamer247 #12
Posted 22 August 2014 - 09:02 PM
Do you have the Energy Cube attached directly to the back of the computer (no peripheral proxy/modem)?

Is the output side of the Energy Cube the side that is attached the the computer?

What versions of MC, Mekanism, ComputerCraft, and Forge are you using?

Yes, directly behind it, no proxy or modem.

Yes.

MC 1.6.4
Mekanism 6.0.5
ComputerCraft 1.63
Forge 9.11.1.965 (Which is the recommended build)
Also, im using OpenPeripheralCore 0.4.1
and OpenPeripheralAddons 0.1.5
Dog #13
Posted 22 August 2014 - 09:07 PM
Hmmm…getMJStored() doesn't work for me with the same versions, it returns "attempt to call a nil" - I have to use getEnergyStored(). Since you're directly connected and you aren't pushing or pulling items I'm pretty sure the correct direction should be "unknown".

I'm curious - what happens if you run this…

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getEnergyStored(side))
end
FXgamer247 #14
Posted 22 August 2014 - 09:08 PM
Hmmm…getMJStored() doesn't work for me with the same versions, it returns "attempt to call a nil" - I have to use getEnergyStored(). Since you're directly connected and you aren't pushing or pulling items I'm pretty sure the correct direction should be "unknown".

I'm curious - what happens if you run this…

local battery = peripheral.wrap("back")
local dir = {
"north",
"west",
"east",
"south",
"up",
"down",
"unknown",
}

for _,side in ipairs(dir) do
  print(side .. ": " .. battery.getEnergyStored(side))
end

temp: 13: attempt to call nil

getEnergyStored() does not show up in var.listMethods()
Edited on 22 August 2014 - 07:09 PM
Dog #15
Posted 22 August 2014 - 09:17 PM
Something is amiss here and I'm not seeing it. I've tried this in both MC 1.6.4 and MC 1.7.10 and getEnergyStored() is returned as a valid method for me while getMJStored() is not. As well, the above code works for me and shows the energy stored in the cube.

Let's stick with the getMJStored() method since that's returned as a valid method for you.

Are you sure the output side of the cube (there is only one output side) is facing the back of the computer?
Edited on 22 August 2014 - 07:17 PM
FXgamer247 #16
Posted 22 August 2014 - 09:19 PM
Something is amiss here and I'm not seeing it. I've tried this in both MC 1.6.4 and MC 1.7.10 and getEnergyStored() is returned as a valid method for me while getMJStored() is not. As well, the above code works for me and shows the energy stored in the cube.

Let's stick with the getMJStored() method since that's returned as a valid method for you.

Are you sure the output side of the cube (there is only one output side) is facing the back of the computer?

I am 110% sure it is. Also, if we are using the same versions, why can you use getEnergyStored() and I can't? If we have the exact same build.
Dog #17
Posted 22 August 2014 - 09:31 PM
I am 110% sure it is. Also, if we are using the same versions, why can you use getEnergyStored() and I can't? If we have the exact same build.
That is a really good question. My downloads are relatively recent, from the original sources (and work when swapped out with the files for a server I play on) so I'm relatively confident that the files on my end are as they should be. I am troubled that "up" and "unknown" caused an error for you - that makes me wonder if one of your mod files may be corrupted in some way. However corruption wouldn't explain why we have different methods available for getting the stored energy.

This may be an issue that a more experienced pro can answer, but my first suspect (based on the errors you are reporting) would be one of your mods. Are you doing this in single player or multiplayer? If multiplayer, is this an MCPC/Cauldron server?

What version of OpenModsLib (if installed) do you have?
Edited on 22 August 2014 - 07:34 PM
FXgamer247 #18
Posted 22 August 2014 - 09:34 PM
I am 110% sure it is. Also, if we are using the same versions, why can you use getEnergyStored() and I can't? If we have the exact same build.
That is a really good question. My downloads are relatively recent, from the original sources (and work when swapped out with the files for a server I play on) so I'm relatively confident that the files on my end are as they should be. I am troubled that "up" and "unknown" caused an error for you - that makes me wonder if one of your mod files may be corrupted in some way. However corruption wouldn't explain why we have different methods available for getting the stored energy.

This may be an issue that a more experienced pro can answer, but my first suspect (based on the errors you are reporting) would be one of your mods. Are you doing this in single player or multiplayer? If multiplayer, is this an MCPC/Cauldron server?

I was on a server up until 7 or 8 minutes ago. It was a local server that was just forge. I thought that it might be the server, but it doesnt work on singleplayer either.

I have a modpack set up with a few mods for the technic launcher. I could PM the link to you if you want, its a hidden modpack.
Dog #19
Posted 22 August 2014 - 09:36 PM
What version of OpenModsLib (if installed) do you have?
FXgamer247 #20
Posted 22 August 2014 - 09:37 PM
What version of OpenModsLib (if installed) do you have?

0.5.1
Dog #21
Posted 22 August 2014 - 09:46 PM
I did some searching with "Mekanism energy cube getMJStored" and the only result that returned with "getMJStored" is this thread. However, searching for getEnergyStored provides a few more useful results including this Reddit thread

The best advice I have at this point is to set up an MC profile with just Forge, CC, OpenP, and Mekanism (redownload them to be sure) and test it there.

Are there any other programs running/auto-starting on the computer you are testing with?

Is the exact version of Mekanism you are running 6.0.5.46 ?
Edited on 22 August 2014 - 07:55 PM
FXgamer247 #22
Posted 22 August 2014 - 10:03 PM
No startup file, and yes same version. Also, I tried what you said, and now everything has the same peripherals as a chest unless it's an openperipherals block. I am so lost now.
Dog #23
Posted 22 August 2014 - 10:13 PM
I'm not sure what you mean by 'same peripherals' - do you mean same peripheral methods?

Did you include OpenModsLib, OpenPeripheralCore and OpenPeripheralAddOns?
Edited on 22 August 2014 - 08:18 PM
FXgamer247 #24
Posted 22 August 2014 - 10:18 PM
I'm not sure what you mean by 'same peripherals' - do you mean same peripheral methods?

Did you include both OpenPeripheralCore and OpenPeripheralAddOns?

Yes and Yes
Dog #25
Posted 22 August 2014 - 10:31 PM
so if you try to set up an energy cube and computer and run the program now you get "attempt to call a nil" ?
FXgamer247 #26
Posted 22 August 2014 - 10:40 PM
so if you try to set up an energy cube and computer and run the program now you get "attempt to call a nil" ?

Yes, that doesn't make any sense at all. I have relogged a few times as just to see if my game was glitching.
Dog #27
Posted 22 August 2014 - 10:44 PM
Hmmm…anything unusual in your logs?

And I guess, just to double check:

Forge
ComputerCraft
Mekanism
OpenPeripheralCore
OpenPeripheralAddons
OpenModsLib

This should be what we're working with, right? Am I missing anything from this list?
Edited on 22 August 2014 - 08:45 PM
FXgamer247 #28
Posted 22 August 2014 - 10:54 PM
Hmmm…anything unusual in your logs?

And I guess, just to double check:

Forge
ComputerCraft
Mekanism
OpenPeripheralCore
OpenPeripheralAddons
OpenModsLib

This should be what we're working with, right? Am I missing anything from this list?

Yeah, im only using those mods, I dont even have optifine. And the log is not being saved for some reason. The latest saved log was on the 17th
Dog #29
Posted 22 August 2014 - 11:12 PM
I'm not sure how to proceed. It sounds like something is awry with your MC install but, again, I'm unsure as to the next steps to take. As much as it's a bummer, I think we'll need to get the help of another pro in here to resolve this.
FXgamer247 #30
Posted 22 August 2014 - 11:17 PM
I'm not sure how to proceed. It sounds like something is awry with your MC install but, again, I'm unsure as to the next steps to take. As much as it's a bummer, I think we'll need to get the help of another pro in here to resolve this.

One last thing we could try, again I have a modpack made up with all the mods my friends and I use. I could give you the link and you could see if you could get it working.
Cranium #31
Posted 22 August 2014 - 11:27 PM
I made a monitoring program with the help of theoriginalbit not too long ago. Try this, and let me know if you're still having issues.
http://pastebin.com/iyPUG8XC

EDIT: Sorry, I had mine multi-purpose built for fluids and ME networks, but if I'm right, should work for your problem. If not, then yeah, bugginess ensues.
Edited on 22 August 2014 - 09:33 PM
FXgamer247 #32
Posted 22 August 2014 - 11:46 PM
I made a monitoring program with the help of theoriginalbit not too long ago. Try this, and let me know if you're still having issues.
http://pastebin.com/iyPUG8XC

EDIT: Sorry, I had mine multi-purpose built for fluids and ME networks, but if I'm right, should work for your problem. If not, then yeah, bugginess ensues.

Your program works, but unfortunately not for the energy cube. It says there is no energy storage detected.
Cranium #33
Posted 23 August 2014 - 12:04 AM
I'll have to do some testing then, because my program is supposed to be universal. Thanks for inadvertantly testing a bug for me. That is strange that it's not returning proper info.

print(textutils.serialize(peripheral.getMethods("back")))
local file = fs.open("dump", "w")
file.write(textutils.serialize(peripheral.getMethods("back"))
file.close()
Try that little bugger there, then tell us the output. That should tell us the available functions for that peripheral. If it doesn't fit on the screen, it'll output a dump file you can access.
FXgamer247 #34
Posted 23 August 2014 - 12:19 AM
I'll have to do some testing then, because my program is supposed to be universal. Thanks for inadvertantly testing a bug for me. That is strange that it's not returning proper info.

print(textutils.serialize(peripheral.getMethods("back")))
local file = fs.open("dump", "w")
file.write(textutils.serialize(peripheral.getMethods("back"))
file.close()
Try that little bugger there, then tell us the output. That should tell us the available functions for that peripheral. If it doesn't fit on the screen, it'll output a dump file you can access.

Here is the contents of the file: http://pastebin.com/d6LMw5kd
Dog #35
Posted 23 August 2014 - 12:33 AM
FXgamer247 - Your link is 'text correct' but clicks through to Cranium's SysMon program instead (for me)…weird.

Cranium - notice that the methods returned include references to MJ (like getMJStored()). I supposedly have the same versions as FXgamer247 but I see things like getEnergyStored() (for 1.6.4) or getStored() (for 1.7.10). I did some searches and couldn't find anything (other than this thread) that had both Mekanism and getMJStored in the results, but plenty with Mekanism and getEnergyStored.

What am I missing here?
Edited on 22 August 2014 - 10:34 PM
Cranium #36
Posted 23 August 2014 - 01:21 AM
Well, just to test, try this:

local energy = peripheral.wrap("back")
print(energy.getMaxMJStored()) --#I assume you'll have to enter "unknown" if it errors here
If it returns a value other than 0, then it should mean that there's no problem, and it's program related. If it returns 0 or nil, then we're in trouble.
FXgamer247 #37
Posted 23 August 2014 - 01:38 AM
Well, just to test, try this:

local energy = peripheral.wrap("back")
print(energy.getMaxMJStored()) --#I assume you'll have to enter "unknown" if it errors here
If it returns a value other than 0, then it should mean that there's no problem, and it's program related. If it returns 0 or nil, then we're in trouble.

*sigh* It returns nil.
Dog #38
Posted 23 August 2014 - 01:47 AM
Just for clarification - does it return nil or do you get an attempt to call nil?

And - did you call it with or without a direction (e.g. "unknown")?
Edited on 22 August 2014 - 11:48 PM
Cranium #39
Posted 23 August 2014 - 01:49 AM
Yeah, that is a problem. It means that even though you're wrapping the peripheral, it's saying that the block is not returning a MaxMJStored amount. Now…just to make sure, you have added some power into the energy cube, correct?

EDIT: actually, Dog brings up good questions. Try his suggestions, definitely.
Edited on 22 August 2014 - 11:50 PM
FXgamer247 #40
Posted 23 August 2014 - 01:57 AM
Just for clarification - does it return nil or do you get an attempt to call nil?

And - did you call it with or without a direction (e.g. "unknown")?

Yes, I tried it with both "unknown" and nothing at all. Neither worked.

Yeah, that is a problem. It means that even though you're wrapping the peripheral, it's saying that the block is not returning a MaxMJStored amount. Now…just to make sure, you have added some power into the energy cube, correct?

EDIT: actually, Dog brings up good questions. Try his suggestions, definitely.

Yes, the energy cube is 100% full. (I also tried it with an empty one)
Dog #41
Posted 23 August 2014 - 02:02 AM
If you'd clarify for me a bit more - what do you mean by 'Neither worked.'? Did they return something (0 or a nil value) or did you get an error? The more data we have to work with the better idea we'll have for which direction to explore next.
FXgamer247 #42
Posted 23 August 2014 - 02:28 AM
If you'd clarify for me a bit more - what do you mean by 'Neither worked.'? Did they return something (0 or a nil value) or did you get an error? The more data we have to work with the better idea we'll have for which direction to explore next.

Without anything returned the error: 2: Not enough arguments, first missing: direction
With "unknown" it returns nil.
Dog #43
Posted 23 August 2014 - 02:36 AM
Do you have Thermal Expansion in your custom mod pack (not the one we're using for testing)?

If so, what versions of CoFH Core and Thermal Expansion?

If not, do you have BuildCraft in the custom mod pack? What version?
Edited on 23 August 2014 - 12:41 AM
Cranium #44
Posted 23 August 2014 - 02:57 AM
Actually, just to expand on his possible moment of enlightenment:
What other energy-producing mods do you have installed?
FXgamer247 #45
Posted 23 August 2014 - 03:09 AM
Actually, just to expand on his possible moment of enlightenment:
What other energy-producing mods do you have installed?

I also have galacticraft and buildcraft. I made a working fuel tank monitor so openperipherals works with that. And the energy storage in galacticraft does return "1", but they do not hold much energy, so I greatly prefer the cubes.
Dog #46
Posted 23 August 2014 - 03:13 AM
Buildcraft is probably why you're seeing getMJStored() while Thermal Expansion is probably why I'm seeing getEnergyStored() - without one of those mods, neither energy method is available
FXgamer247 #47
Posted 23 August 2014 - 03:26 AM
Buildcraft is probably why you're seeing getMJStored() while Thermal Expansion is probably why I'm seeing getEnergyStored() - without one of those mods, neither energy method is available

That is actually a really smart idea, I'll install thermal expansion as soon as I get back on my computer.
Dog #48
Posted 23 August 2014 - 03:30 AM
Here are the versions I'm using for testing…

CoFH Core 2.0.0.5
Thermal Expansion 3.0.0.7
FXgamer247 #49
Posted 23 August 2014 - 03:47 AM
YES! It now lets me use var.getEnergyStored()! Also Crainium, your program works great. Thank you both for your help!
Dog #50
Posted 23 August 2014 - 03:50 AM
You're welcome! Glad we all got it sorted :)/>