Sign in to follow this  
Lolsenstein

[Lua] Error when automatically creating a table

Recommended Posts

Lolsenstein    100
I am making a text-based Minesweeper for lua, and I am using Tables for graphics.
This is what I use to initialize it:
[code]for i = 1, 16 do
a = {a[i]}
a[i] = G
end[/code]

However, I get this error:
[code]lua: Minesweeper.lua:7: attempt to index global 'a' (a nil value)
stack traceback:
Minesweeper.lua:7: in main chunk
[C]: ?
>Exit code: 1[/code]

As far as I can tell, my code should be correct.
Can someone please correct my idiotic code? Haven't programmed in about a year.

Share this post


Link to post
Share on other sites
ddn3    1610
Looks like a is undefined.

you have to define a somewhere atleast like this

a={}

that creates a new table called a, in global namespace.

local a={}

will create one in local namespace..

Good Luck!

-ddn

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this