Instances have their own state once created. If the class supports it, you can pass arguments when you create an instance, allowing you to customize the state of each instance.
Multiple instances can be created from a single class or subclass. Instances can be passed to other classes and subclasses as well.
An instance name is generally represented as a lowercase string. For example, "person" is a good instance identifier.
Instance methods are always called using the Lua colon (:) syntax, for example:
--using colon syntax local name = person:getName() --THIS WILL NOT WORK --using dot syntax local name = person.getName()
To get or set any properties of the instance, you use the standard dot (.) syntax, for example:
--get local name = person.name --set person.name = "Billy"
local Person = require("classes.Person") local p1 = Person:new("Tammy") local p2 = Person:new("Jimmy") print(p1:getName()) --> Tammy print(p2:getName()) --> Jimmy
See the class example here to get an idea of what the class looks like that produces the instances in the example above.