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

Attempt to compare nil with number?

Started by crazygoattoe, 06 January 2013 - 04:29 PM
crazygoattoe #1
Posted 06 January 2013 - 05:29 PM
I just typed a quarry program into an turtle on SSP and when I try to run it it lets me input the length, width, and height, but then it says "quarry:149: attempt to compare nil with number"

Here is the code around line 149:

volume = x*y*z
area = x*z

if maxslots > 15 then <———that's line 149
maxslots = 15
end
if Cdouble == 1 then
maxsize = maxsize/2
end

Any help would be great, I don't know much about code, but I've been able to debug it (mostly typos) up to this point
Luanub #2
Posted 06 January 2013 - 07:01 PM
Does maxslots have a value prior to the if statement? Without seeing the rest of the code its a little difficult to help. About the advise I can give is for you to print maxslots prior to the if statement to see what its value is.
remiX #3
Posted 07 January 2013 - 12:26 AM
Does maxslots have a value prior to the if statement? Without seeing the rest of the code its a little difficult to help. About the advise I can give is for you to print maxslots prior to the if statement to see what its value is.

I'll have a go and say it doesn't because of the error, the only nil value there can be 'maxslots'
crazygoattoe #4
Posted 07 January 2013 - 04:49 AM
how do I define maxslots so that it still works with this part of the program? The full code is here: http://pastebin.com/u3CTvenK and the error in this code would be appearing on line 167
remiX #5
Posted 07 January 2013 - 04:54 AM
Well, can you tell us exactly what the variable is supposed to be doing?
ChunLing #6
Posted 07 January 2013 - 10:01 PM
–This is how many (theoretical) slots it will fill with cobble. e.g. 13 allows 13 slots for cobble (or other stack) and 2 slots for other things.
–Maximum here is 15 because 16 is for fuel
maxslots = 13
Okay, I'm lost. You clearly define maxslots at the beginning of the program, it's the first thing that gets done, and maxslots is global. You don't call any other programs that I can see (which could pose a problem), and you never redefine maxslots before the comparison.

Best I can suggest is to add the local keyword to the initial definition of maxslots just in case something else is accessing the global maxslots, but I can't see what.