TabloidA
TabloidA

Reputation: 67

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. "attempt to index global 'player' (a nil value)"

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.

So Stack Overflow, my question is, What should I do to fix this?

Upvotes: 0

Views: 1903

Answers (1)

Andy Nonomous
Andy Nonomous

Reputation: 49

Etan Reisner had the correct answer here. 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.

Upvotes: 0

Related Questions