1
-- Make your Penguin class, for your Penguin object
4
-- Variable to hold the colour of every penguins fur
5
local furColor = "BLACK"
9
This function is called every time you create a new instance of the class.
10
It "initiates" your instance, and you can, for example, set some default values,
12
Not so important at this point ;)
14
function Penguin:_init()
15
self.name = "nonameyet"
16
-- "self." means "from this instance..."
17
-- So "self.name" translates to "the name variable from a particular instance of the Penguin class"
18
-- It means that every time you create a new instance of this class, this instance will
19
-- automatically have a variable called "name" with the value "nonameyet"
22
-- swim(); Instance function
23
-- Arguments: 2 strings: from, to
24
-- no return value, prints something to console
25
function Penguin:swim(from, to)
26
print("The penguin is swimming from: " .. from .. ", to: " .. to)
29
-- getFurColor(); Class function
31
-- returns the colour variable of the penguin class as a string
32
function Penguin.getFurColor()
36
-- namePenguin(); Instance function
37
-- Arguments: one string: name
38
-- sets the name variable of the instance to the argument which is passed to the function
39
function Penguin:namePenguin(name)
43
-- getName(); Instance function
45
-- returns the name variable of the instance as a string
46
function Penguin:getName()
b'\\ No newline at end of file'