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

__ div on nil and number -- need fresh pair of eyes (awaiting next crash)

Started by menz, 13 July 2013 - 10:54 AM
menz #1
Posted 13 July 2013 - 12:54 PM
I cannot for the life of me figure out the error, in this program.

here is the error thrown: 226: attempt to preform arithmetic __div on nil and number

heres the thing, at no time does it have nil stored in the varibles. and the program runs fine for the longest.

i think its server lag causeing it. anyways is there a way to fix it so the program wont crash?

here is the pastebin code: http://pastebin.com/87YfBAgR

thanks.

edit* using cc 1.53
albrat #2
Posted 13 July 2013 - 01:18 PM
I would add a line or two of code at line 252-253 that prints the results of x[ varibles ]

so you can see what it outputs at x["energyL"]

I will hazard a guess you are getting a nil value there…


	local totalEnergy = 0
	for i = 2, 4 do
		local _,_,_,x = reader.get(i)
---[[ testcode
	   print("testcode start")
	   print(i)
	   print(x["eneryL"])
	   print("testcode end")
	   sleep(2)
--]]
		totalEnergy = totalEnergy + x["energyL"]
	end
    mfsuReading = totalEnergy
end

menz #3
Posted 13 July 2013 - 01:57 PM
change implimented – however the crash doesnt happen often, it might be a while to report if thats it.
albrat #4
Posted 14 July 2013 - 04:20 PM
Could it be the power returning as 0. aka a nil value

if it is… then we can control the the error by running a quick check on x["energyL"]


if x["energyL"] == nil then x["energyL"] == 0 end

this will handle a nil value and make it zero instead. (place in the same location as the testcode - After the grab of information but before the math.
Grim Reaper #5
Posted 14 July 2013 - 05:15 PM
This is just a quick guess, but make sure that the scope that you're defining fuelTimer in is global. Try defining it in the global scope before your script hits its main part.