Creating functions is as easy as creating a simple variable. Functions act as variables:
local myFunction = function (text)
print(text)
end
function myFunction () … end is only a syntactical sugar. That's why you can assign functions to any variable you want.
Also, this line here:
zombie = object
Variables don't actually hold a table, only it's pointer to the memory, which means that now those two variables hold
the same table. To have a copy of the table you could make a function which would take all contents from a table and put it into a new table.
It looks like you're creating a some sort of game using 'classes' in Lua. Many people prefer to use
setmetatable to 'copy' and make a new instance of that table:
Using your metod:
local myClass = {
text = "Hello"
}
local myClassInstance = myClass
print(myClassInstance.text) -->> Hello
print(myClass.text) -->> Hello
myClassInstance.text = "World"
print(myClassInstance.text) -->> World
print(myClass.text) -->> World
Using setmetatable:
local myClass = {
text = "Hello"
}
local myClassInstance = setmetatable({}, {__index = myClass})
print(myClassInstance.text) -->> Hello
print(myClass.text) -->> Hello
myClassInstance.text = "World"
print(myClassInstance.text) -->> World
print(myClass.text) -->> Hello
If you have questions just ask!
Off topic: is there a chance you're from in Lithuania :P/>/>?