简体   繁体   English

LOVE2d [ERROR]尝试索引全局“玩家”(nil值)

[英]LOVE2d [ERROR] attempt to index global 'player' (a nil value)

So I'm playing around with the Grid-Locked Player Tutorial from the LOVE2d wiki, and I come across this error when I try to run it. 因此,我在玩LOVE2d Wiki上的Grid-Locked Player Tutorial,尝试运行该错误时遇到了此错误。 "attempt to index global 'player' (a nil value)" “尝试索引全局'玩家'(nil值)”

Full Code: My Code 完整代码: 我的代码

Here's the specific code snippet that was causing the problem. 这是引起问题的特定代码段。

if enemyFOV <= player.grid_x then
    shoot()
end

I've already looked at other similar questions on this site, and none seemed to apply to my problem. 我已经在该网站上查看了其他类似的问题,但似乎没有一个适用于我的问题。 Except for one that had the solution of using 除了有使用解决方案的

return

after the shoot() function. 在Shoot()函数之后。

So Stack Overflow, my question is, What should I do to fix this? 所以堆栈溢出,我的问题是,我应该怎么做才能解决此问题?

Etan Reisner had the correct answer here. Etan Reisner在这里有正确的答案。 The code snippet that is giving you the error resides outside of any function. 给您错误的代码片段位于任何函数之外。 If you move the offending code inside of love.update(), your problem should be solved. 如果将有问题的代码移到love.update()内,则应解决您的问题。

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

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