简体   繁体   中英

Attempt to compare nil with number on object.x coordinate

I you all, when I try to reload a scene in CORONA SDK using the director class, I get "Attempt to compare nil with number" on

if vec.x < _W/2-180 then

where vec is

local vec = display.newImage("main_char.png", _W/2-180, _H/2+300)
vec.x = _W/2-180
vec.y = _H/2+300
localGroup:insert(vec)

I sincerely I haven't find out how to solve it.

OK so I can't see any typos, and the code is indicating that vec.x is nil ( vec is not nil since the error would be attempt access global vec nil, and _W is not nil because the error would say attempt to perform arithmetic on nil. Can't see anything wrong with what you show, so cause is in code not shown.

I would print(type(vec.x)) anywhere that you access vec.x (after you set it, after you insert it in localGroup, just before your condition check): search for all places where vec.x is set, one of them must be setting it to something nil (like vec.x = someFunction(...) and someFunction returned nil ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM