61 posts
Location
Christchurch, New Zealand
Posted 03 August 2014 - 02:20 PM
I'm using Computercraft to read to resonant energy cells from Thermal Expansion, which then sends it to a server computer to activate a nether star generator. I'm using wired modems to read the energy cells however, and with not much knowledge of wired modems I would like some help. It errors out on line 22: attempt to perform arithmetic __div on nil and number
The pastebin link is
http://pastebin.com/nyyuXTHFI'm not sure on how to get it to use methods which require a string with wired modems.
3057 posts
Location
United States of America
Posted 03 August 2014 - 04:02 PM
Well, the error tells us that 1 of these is returning nil. Other than that, I'm not sure what could be wrong.
cellOneEnergyStored = cellOne.getEnergyStored("cofh_thermalexpansion_energycell_0")
cellOneMaxEnergy = cellOne.getMaxEnergyStored("cofh_thermalexpansion_energycell_0")
61 posts
Location
Christchurch, New Zealand
Posted 03 August 2014 - 04:50 PM
I realised that, however I don't see the problem being with them, they work when a computer is placed on top on energy cell to read the energy without any wired modem, but I want it to be one computer, not 2
3057 posts
Location
United States of America
Posted 03 August 2014 - 05:43 PM
Are you sure the name is correct? It will say the name of the attached peripheral in chat when you connect the wired modem.
31 posts
Posted 03 August 2014 - 05:44 PM
You should just be doing the following, so long as cellOne is a wrapped peripheral.
cellOneEnergyStored = cellOne.getEnergyStored()
You're providing an argument specifying the name of the peripheral and you already did that when you did
cellOne = peripheral.wrap("cofh_thermalexpansion_energycell_0")
If you want to call functions without first wrapping peripherals you can use the following
peripheral.call("cofh_thermalexpansion_energycell_0", "getEnergyStored")
Make sure you check out the
Peripheral API page on the wiki to get more info on working with peripherals in ComputerCraft.
Also, make sure that you're right clicking the wired modem attached to the peripheral, in this case the energy cell, and that it turns red and displays the name of the peripheral in the chat box. Although, I'm assuming you've already done this correctly because you've already used the name of the cells.
Edited on 03 August 2014 - 03:55 PM
61 posts
Location
Christchurch, New Zealand
Posted 03 August 2014 - 06:18 PM
I figured out the issue, it was a simple typo, stupid me!
cellOneEnergyPercent = cellOneEnergyStored/cellOneMaxEnergy*100
In this it only had 1 l in "cellOneEnergyStored" Stupid me didn't realise it haha but I fixed that and it's working fine