[solved] Cannot index global variable?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

[solved] Cannot index global variable?

Post by Tesselode »

I want to have multiple bullets, so I'm keeping track of them with an index. When I run this:
player_bullet_x[player_bullet_amount+1]=player_x

I get the following error:
main.lua:31: attempt to index global 'player_bullet_index' (a nil value)

How can I add an index to a global variable without LOVE throwing up?
Last edited by Tesselode on Sat Jul 24, 2010 2:22 am, edited 1 time in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Cannot index global variable?

Post by Robin »

you have to make a table and give it that name:

player_bullet_index = {}

In Lua, any undefined variables are nil, which you can't index.
Help us help you: attach a .love.
User avatar
Tesselode
Party member
Posts: 555
Joined: Fri Jul 23, 2010 7:55 pm

Re: Cannot index global variable?

Post by Tesselode »

Hold on a second; I made a typo. The variable it was complaining about was "player_bullet_x." But adding "player_bullet_x={}" to love.load fixed the problem. So thanks!
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 39 guests