readme

Sat, 27 Mar 2010 17:43:08 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 27 Mar 2010 17:43:08 +0000
changeset 0
cc66ad6b0d75
permissions
-rwxr-xr-x

Initial commit (importing from old SVN repo which got lost)

0
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 # XMOO Readme file.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 #Creating a new class
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 In this example, we will create a torch.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 Start with the line:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 classes.obj_torch = { } -- This creates an empty object
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 What you call the class does not matter, it is not visible to users.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 Now we must define some things, such as its name, and what it looks like, its properties.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13 classes.obj_torch._properties = {
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 name = "torch",
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 longname = "An electric torch",
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 desc = "A small portable electric torch, to help you see when it is dark"
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 }
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 Simple, eh? :)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 Now, we want the user to be able to do things with the torch, let's say that 'twisting' it, switches it on and off.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 So we must define the method 'twist':
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 function classes.obj_torch:twist(info)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26 end
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 info is a variable we get, that contains information useful to use, such as who twisted it (info.person), and what room we are in (info.room), etc.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 Now we must also keep track of whether the torch is lit or unlit. We will store this as a property. In a method, 'self' always refers to the curent object.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 function classes.obj_torch:twist(info)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 if self._properties.state == "lit" then self._properties.state == "unlit" -- if it is lit, make it unlit
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 else self._properties.state == "lit" end -- Otherwise, make it lit
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 end
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 Very good, but we must show everyone in the room what is going on:
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39 function classes.obj_torch:twist(info)
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 if self._properties.state == "lit" then
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 self._properties.state == "unlit" -- if it is lit, make it unlit
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 self._properties.desc = "A small portable electric torch, to help you see when it is dark. It is not lit."
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 info.person:_say("/me turns off the torch")
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 else
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 self._properties.state == "lit" -- Otherwise, make it lit
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 self._properties.desc = "A small portable electric torch, to help you see when it is dark. It is lit."
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 info.person:_say("/me lights the torch")
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 end
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 end
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 As you can see, the colon ':' is used to call methods, or functions of another object. Remember that people are objects too!
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 The default 'look' method uses the 'desc' property, so we have changed it, to show whether the torch is lit or not.
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 It's done!
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55
cc66ad6b0d75 Initial commit (importing from old SVN repo which got lost)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 More to come, including creating new rooms :)

mercurial