0 Members and 3 Guests are viewing this topic.
Code: [Select]Bar = class(Foo)So this will also call Foo:init() after it assigns the table of Bar? That's interesting.
Bar = class(Foo)
What's the difference then ? Foo() will call Foo:init() after the copy (the constructor).
@adriweb: Yeah I've seen it, I understand the actual definition even less. Sorry.
Quote from: Jonius7 on July 29, 2013, 08:45:42 amSo clarification,Code: [Select]ball = class() -- creates a class called ball using the class function that is predefinedfunction ball:init(speed, size) -- initialises the class, it can be called by just ball() elsewhere in the code self.speed = spd -- these are added to the table, ball? self.size = sizeendYes (and it's 'speed' not 'spd').
So clarification,Code: [Select]ball = class() -- creates a class called ball using the class function that is predefinedfunction ball:init(speed, size) -- initialises the class, it can be called by just ball() elsewhere in the code self.speed = spd -- these are added to the table, ball? self.size = sizeend
ball = class() -- creates a class called ball using the class function that is predefinedfunction ball:init(speed, size) -- initialises the class, it can be called by just ball() elsewhere in the code self.speed = spd -- these are added to the table, ball? self.size = sizeend
function Units:init(plr, x, y, str, move, opt) -- player, xy position on map, strength, movement, options self.plr = uplr self.x = ux self.y = uy self.str = ustr self.move = umove self.opt = {}end
function Units:init(plr, x, y, str, move, opt) -- player, xy position on map, strength, movement, options self.ran = plr self.dom = x self.hah = y self.yea = str self.ble = move self.see = {} self.new = 10end
function Units:init(plr, x, y, str, move, opt) --these are not your self. variables, they are just values that are passed when it is called. self.plr = plr --Notice how you are setting the self. variable to the variable passed in the constructor. self.x = x self.y = y self.str = str self.move = move self.opt = optend
your parameters must be equil to your variable.
local foo = 42{ -- new scope, it can a function, for, while, etc .. local foo = 69 print(foo) -- prints 69}print(foo) -- prints 42
Foo = class()function Foo:init(x, y, z) self.x = x self.y = y self.z = zend
Foo = class()function Foo:init(xx, yy, zz) x = xx y = yy z = zzend
Foo = class()function Foo:init(xx, yy, zz) self.x = xx self.y = yy self.z = zzend