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

Whenever the drum is empty I get this error...

Started by @itsogman, 17 July 2015 - 03:59 PM
@itsogman #1
Posted 17 July 2015 - 05:59 PM
Whenever the drum is empty I get this error, if anyone can help it would be much appreciated .

Error: http://gyazo.com/035286dcd63640bec4a5eb10b7903184

He is a link to my code: http://pastebin.com/TKpi0b1i
Cranium #2
Posted 17 July 2015 - 06:18 PM
Moved to Ask a Pro.
HPWebcamAble #3
Posted 17 July 2015 - 06:52 PM
Err, did you look at line 43?


When the drum is empty contents will be nil, because there is no contents

Its a simple fix really:

	local tankInfo = con[2].getTankInfo()
	local contents = tankInfo[1].contents
	local amount = contents.amount
	samount = tostring(amount)
	scap = "256000"

	if samount == nil then
	  samount = "0"
	end
Change this to:

	local tankInfo = con[2].getTankInfo()
	local contents = tankInfo[1].contents
	local amount = 0
	if contents then
	  amount = contents.amount
	end
	samount = tostring(amount)

	if samount == nil then
	  samount = "0"
	end

I think there is one other place you reference 'contents.amount', you'll need to change that as well.
Edited on 17 July 2015 - 04:53 PM
Lupus590 #4
Posted 17 July 2015 - 06:54 PM
when the drum is empty the variable contents in nil, check that it is not nil before using it

:ph34r:/>

In HPWebcamAble's solution you don't need to convert it to a string

my version of the solution:


local tankInfo = con[2].getTankInfo()
local contents = tankInfo[1].contents
local amount = 0
if contents then
  amount = contents.amount
else
  amount = "0"
end
Edited on 17 July 2015 - 04:58 PM
@itsogman #5
Posted 17 July 2015 - 07:07 PM
Well that fixed it but now i have this error: http://gyazo.com/bc19ba5764e3cdb7d415dfd4411df0a4
flaghacker #6
Posted 17 July 2015 - 07:58 PM
Well that fixed it but now i have this error: http://gyazo.com/bc1...415dfd4411df0a4

With you new line 25 being?
HPWebcamAble #7
Posted 17 July 2015 - 08:13 PM
Well that fixed it but now i have this error: http://gyazo.com/bc1...415dfd4411df0a4

Again, you are accessing contents, so you need to check if it is nil:

function fluidDisplay()
  local tankInfo = con[2].getTankInfo()
  local contents = tankInfo[1].contents
  local name = contents.rawName        --# Check if 'contents' is nil BEFORE this
  local maxF = "256000"
  addText(11,57,name,0xFF0000,1)
end

With you new line 25 being?
Err… What?
flaghacker #8
Posted 17 July 2015 - 08:51 PM
With you new line 25 being?
Err… What?

Line 25 on his pastebin:

local maxF = "256000"
That can't throw any errors…
HPWebcamAble #9
Posted 17 July 2015 - 09:49 PM
Line 25 on his pastebin:

local maxF = "256000"
That can't throw any errors…

Ohh, that makes sense. I'm still not sure what you said, but oh well.

That's what I was thinking, and I assumed it was the line above it (like I pointed out above)
Anavrins #10
Posted 17 July 2015 - 11:01 PM
Well that fixed it but now i have this error: http://gyazo.com/bc1...415dfd4411df0a4
Can you post the updated code?