return table problem

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
willthewarlock
Prole
Posts: 3
Joined: Sat Feb 07, 2009 6:16 pm

return table problem

Post by willthewarlock »

I'm making a GUI library and I get error LFrame is nil value. Frame is a table in a other file(which is included in the GUI library)

Main Program:

Code: Select all

require('GUI.lua')

function load()
	local var = love.graphics.newImage('test.gif')
	LFrame = GUI:Create('Frame')
	LFrame:SetPos(10,10)
	LFrame:SetSize(100,100)
	LFrame:SetTitle('TEST')
	LFrame:SetBackgroundPic(var)
	LFrame:Show(true)
end 
GuiLibrary:

Code: Select all

GUI = { 
	Create = function(obj)
		if obj == 'Frame' or obj == 'Window' then
			c = {}
			for k, v in pairs(Frame) do
				c[k] = Frame[k]
			end
		end
		Objects[#Objects + 1] =  c
		return c
	end,
        -- more code
}
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: return table problem

Post by bartbes »

That's easy, you use GUI:Create, this means that the function GUI.Create should have the following prototype:
function (self, obj)

Because this isn't the case, obj is set as self, instead of the argument provided, so, obj == GUI, this means that the check fails, c is never set and there is a nil value returned.
willthewarlock
Prole
Posts: 3
Joined: Sat Feb 07, 2009 6:16 pm

Re: return table problem

Post by willthewarlock »

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests