Image assignment issue

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
TayTree
Prole
Posts: 3
Joined: Thu Dec 26, 2013 2:19 pm

Image assignment issue

Post 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)
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Image assignment issue

Post 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. :)
TayTree
Prole
Posts: 3
Joined: Thu Dec 26, 2013 2:19 pm

Re: Image assignment issue

Post 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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Image assignment issue

Post 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
TayTree
Prole
Posts: 3
Joined: Thu Dec 26, 2013 2:19 pm

Re: Image assignment issue

Post by TayTree »

Thank you very much. :D I'm only used to (my favourite) Assembler, Pascal and some C.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Altostratus, Google [Bot], Semrush [Bot] and 4 guests