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

Silly variable not existing problem

Started by Lasere123456, 22 January 2020 - 07:23 PM
Lasere123456 #1
Posted 22 January 2020 - 08:23 PM
Hey,

I bet this is super simple but i can't make it work :/

https://pastebin.com/cbuigeru

The program works fine as long as their is something in all the 3 tanks being checked.
however if one is emty, then it gets a attemted to index a nill value error.

i tried to fix this whith this:
  • if tank3.contents.amount == nil then
  • print("nil")
  • end

i also tried forcing tank2.contents.amount and tank3.contents.amount to always be 0 or correct, but this failed also.

(I did not write inn anything to happen yet, if it the value was nil, since this did not work)

Any tips in how to make this work?

(also i am going to add local to evryting wend it works, also sry for bad English )

Thanks
Lupus590 #2
Posted 22 January 2020 - 10:48 PM
tank3.contents is nil if ithas nothing in it. you can fix this by doing

if tank3.contents == nil or tank3.contents.amount == nil then
  print("nil")
end