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?
[solved] Cannot index global variable?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[solved] Cannot index global variable?
Last edited by Tesselode on Sat Jul 24, 2010 2:22 am, edited 1 time in total.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Cannot index global variable?
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.
player_bullet_index = {}
In Lua, any undefined variables are nil, which you can't index.
Help us help you: attach a .love.
Re: Cannot index global variable?
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!
Who is online
Users browsing this forum: Google [Bot] and 39 guests