How do I have to handle function calls using the character from above then, like for example this one:
local moveObject moveObject = function (object) object.x=object.x+1 end moveObject (character)
or like this one…
local moveObject2 moveObject2 = function (object) local myObject=object myObject.x=myObject.x+1 end moveObject2 (character)
Is there something to think of regarding memory, other than to destroy “character” later?
the extra local in the second form is unnecessary (and in fact a bit wasteful), all you need is:
local function moveObject(obj)
obj.x = obj.x + 1
end
moveObject(character)
– or equivalent OOP style:
function character:move()
self.x = self.x + 1
end
character:move()
neither form has any intrinsic memory issues to worry about (when character is nil’ed, first form’s function will remain, second form’s function will be released along with object; either is fine, just depends on how you might be reusing them for other objects, or not)
How do I have to handle function calls using the character from above then, like for example this one:
local moveObject moveObject = function (object) object.x=object.x+1 end moveObject (character)
or like this one…
local moveObject2 moveObject2 = function (object) local myObject=object myObject.x=myObject.x+1 end moveObject2 (character)
Is there something to think of regarding memory, other than to destroy “character” later?
the extra local in the second form is unnecessary (and in fact a bit wasteful), all you need is:
local function moveObject(obj)
obj.x = obj.x + 1
end
moveObject(character)
– or equivalent OOP style:
function character:move()
self.x = self.x + 1
end
character:move()
neither form has any intrinsic memory issues to worry about (when character is nil’ed, first form’s function will remain, second form’s function will be released along with object; either is fine, just depends on how you might be reusing them for other objects, or not)