Posted 09 September 2015 - 10:34 AM
Hi !
I post this topic because I'm encountering a problem programming a program.
I just wanna say that my English could be awful, I'm French, and I'm looking for help from you :)/>
This program take energy information from an Energy Cube, add it in a table called "energy" and will calculate the average energy consumption of my base.
When I run the program, It writes on the screen the following error : "EnergyConsumption:67: attempt to perform arithmetic __sub on number and nil"
There is the parts of the code where the problem si encountered :
First, I set up my tables :
"diff" will take the results of the difference between 2 energy measures. For example, diff[1] = energy[2] - energy[1]
So, this is the part of the code where the problem is encountered :
-> Energy measures (currently working, "nac" variable is the number of measures the program will do) :
I hope my English was enough understandable, and I hope you'll can help me too !
I post this topic because I'm encountering a problem programming a program.
I just wanna say that my English could be awful, I'm French, and I'm looking for help from you :)/>
This program take energy information from an Energy Cube, add it in a table called "energy" and will calculate the average energy consumption of my base.
When I run the program, It writes on the screen the following error : "EnergyConsumption:67: attempt to perform arithmetic __sub on number and nil"
There is the parts of the code where the problem si encountered :
First, I set up my tables :
local energy = {}
local diff = {}
p = peripheral.wrap("left")
"energy" will take all the energy measures, E1 = … for the first measure, E2 = … for the second, etc…"diff" will take the results of the difference between 2 energy measures. For example, diff[1] = energy[2] - energy[1]
So, this is the part of the code where the problem is encountered :
-> Energy measures (currently working, "nac" variable is the number of measures the program will do) :
for i=1, nac do
E = p.getEnergyStored()
energy[i] = E
end
Now, this is the part of the code where the error message goes :for i=1; nac do
diff[i] = energy[i] - energy[i+1]
end
I hope my English was enough understandable, and I hope you'll can help me too !