Page 1 of 1

Array Argument Not Working

Posted: Thu Jul 31, 2014 5:07 am
by nmimagine
So I'm making a GUI library for my game, a button class. Here's the snippet of my codes :

Code: Select all

button = class:new()

function button:init(opt)
	self.x = opt.x
	self.y = opt.y

	self.command = opt.command

	self.mode = opt.mode

        -- And so on
end
Yeah, as you see, I used Bart van Strien's "Simple Educative Class System", but I think that's not the problem...

And for the implementation....

Code: Select all

	playbtn = button:new()
	playbtn:init({
				x = 525,
				y = 400,
				command = startgame,
				mode = "text",
				text = "Play",
				font = fonts.mutlu,
				color1 = {153,153,153},
				color2 = {255,255,255}
				})
But those codes result an error :
Attempt to index local 'opt' (a nil value)
I've trying a lot of things, but none of them solve the problem. One of them is from LUA documentation, here's the link :
http://www.lua.org/pil/5.3.html
And also from this forum, the closest one, but I think it's different from my case:
viewtopic.php?f=4&t=9187

I have no idea what to do, and where I should ask this question (Love2d forum, or another programming forum like stackoverflow). But here's my question, I need your help....

Re: Array Argument Not Working

Posted: Thu Jul 31, 2014 9:03 am
by bartbes
When a new object gets created with SECS, using the new method, that already calls init for you. So instead of calling new without arguments, and then calling init with arguments, just call new with arguments and you're set.

Re: Array Argument Not Working

Posted: Sat Aug 02, 2014 6:48 am
by nmimagine
MANY THANKS!!! :ultraglee: :ultraglee: :ultraglee: :ultraglee: