Page 1 of 1
Image assignment issue
Posted: Thu Dec 26, 2013 2:26 pm
by TayTree
Hi everyone,
I'm wondering why I can't do the following:
Code: Select all
abc[1] = love.graphics.newImage('Button_normal.png')
I get the exception:
attempt to index global 'abc' (a nil value)
Re: Image assignment issue
Posted: Thu Dec 26, 2013 2:34 pm
by Roland_Yonaba
You need to declare the table first.
Code: Select all
abc = {}
abc[1] = love.graphics.newImage('Button_normal.png')
Also,
these links might help.
Re: Image assignment issue
Posted: Thu Dec 26, 2013 2:51 pm
by TayTree
Actually, the case is more complicated:
Code: Select all
function love.load()
for i=1,#buttons do
button_images[i][1] = love.graphics.newImage(buttons[i][5])
button_images[i][2] = love.graphics.newImage(buttons[i][6])
end
love.graphics.setBackgroundColor(0, 0, 0)
love.mouse.setVisible(true)
end
Even with "button_images = {}" it doesn't function. I think it's a nesting problem.
Re: Image assignment issue
Posted: Thu Dec 26, 2013 3:15 pm
by Roland_Yonaba
Code: Select all
function love.load()
button_images = {}
for i=1,#buttons do
button_images[i] = {}
button_images[i][1] = love.graphics.newImage(buttons[i][5])
button_images[i][2] = love.graphics.newImage(buttons[i][6])
end
-- snip
end
Re: Image assignment issue
Posted: Thu Dec 26, 2013 3:22 pm
by TayTree
Thank you very much.
I'm only used to (my favourite) Assembler, Pascal and some C.