209 posts
Location
Denmark
Posted 01 October 2015 - 11:54 PM
im trying to get my computer to check my Railcraft tanks for the content..
but im running into the problem when using multiple tanks stacked, that the program crashes when one of them is empty, because the info im pulling, is no longer valid..
how do i put in a check in a table to see if a certain string is available??
2427 posts
Location
UK
Posted 02 October 2015 - 12:12 AM
if tank.contents then --#does tank.contents have a value
--#do something with tank.contents
end
--#you can take this one step more too:
if tank then --#do I have a tank?
if tank.contents then --#does tank have something in it?
--#do something with tank.contents
end
end
this works because in an if statement, nil returns false. If something is empty then it 'contains' nil
Edited on 01 October 2015 - 10:15 PM
1080 posts
Location
In the Matrix
Posted 02 October 2015 - 12:16 AM
if tank == nil then
print("OH HEY WE HAVE NOTHING IN THIS TANK")
end
Pretty sure i've solved this problem with you before dusty
Edit: Kinda ninja'd, although I was looking for code that I've written with dustmuz that covered this exact scenario…
Edited on 01 October 2015 - 10:17 PM
209 posts
Location
Denmark
Posted 02 October 2015 - 05:44 PM
This was solved using the example given by Lupus590 and Dragon's help via skype :D/>