简体   繁体   English

尝试将nil与object.x坐标上的数字进行比较

[英]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 所有人,当我尝试使用Director类在CORONA SDK中重新加载场景时,出现“尝试将nil与数字进行比较”

if vec.x < _W/2-180 then

where vec is vec在哪里

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. 好的,所以我看不到任何错字,并且代码表明vec.x为nil( vec不是nil,因为错误将是尝试访问全局vec nil的结果,而_W不是nil,因为错误将表明尝试执行的错误nil上的算术运算。您看到的内容看不到任何错误,因此原因是未显示的代码。

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 ). 我将在您访问vec.x任何位置(设置后,将其插入localGroup中之后,在进行条件检查之前print(type(vec.x)) :搜索设置了vec.x所有位置,一个其中的一个必须将其设置为nil(例如vec.x = someFunction(...)并且someFunction返回nil )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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