lua - Checking if a table has been created not working -


using code:

function createnewbody(name,mass) if not world.body[name]==nil     print("this body has been created. maybe meant update it's values?\n") else     world.body[name]={mass=m,x=0,y=0,xaccel=0,yaccel=0,xr=0,yr=0,properties={gaseous=false,texture=""}}     world.bodies=world.bodies+1 end end 

this code shows no errors, when bind createnewbody(moon,1.622) key , use it, lets me spam key without showing error message.

and, yes, have defined world.bodies , world.body

not world.body[name]==nil parsed (not world.body[name])==nil. since result of not boolean, never nil.

try not(world.body[name]==nil) or world.body[name]~=nil.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -