~etc-pgh-launchpad/wildpockets/trunk

« back to all changes in this revision

Viewing changes to baseresources/wild pockets team/tutorials/scriptingintro/penguin.lua

  • Committer: etc-pgh-launchpad at cmu
  • Date: 2010-11-30 20:56:30 UTC
  • Revision ID: etc-pgh-launchpad@lists.andrew.cmu.edu-20101130205630-0blbkcz28ovjl8wj
Committing the Wild Pockets code base to Launchpad.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Make your Penguin class, for your Penguin object
 
2
Penguin = Class.new()
 
3
 
 
4
-- Variable to hold the colour of every penguins fur
 
5
local furColor = "BLACK"
 
6
 
 
7
--[[
 
8
_init() :
 
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,
 
11
like a default name.
 
12
Not so important at this point ;)
 
13
--]]
 
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"
 
20
end
 
21
 
 
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)
 
27
end
 
28
 
 
29
-- getFurColor(); Class function
 
30
-- no arguments
 
31
-- returns the colour variable of the penguin class as a string
 
32
function Penguin.getFurColor()
 
33
    return furColor
 
34
end
 
35
 
 
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)
 
40
    self.name = name
 
41
end
 
42
 
 
43
-- getName(); Instance function
 
44
-- no arguments
 
45
-- returns the name variable of the instance as a string
 
46
function Penguin:getName()
 
47
    return self.name
 
48
end
 
 
b'\\ No newline at end of file'