xmoo-hg

XMOO - MUD/MOO as an XMPP MUC component

hg clone https://code.matthewwild.co.uk/xmoo-hg

tip: cc66ad6b0d75 (2010-03-27)

# XMOO Readme file.

#Creating a new class
In this example, we will create a torch.

Start with the line:
	classes.obj_torch = { } -- This creates an empty class

What you call the class does not matter, it is not visible to users.

Now we must define some things, such as its name, and what it looks like, its properties.

	classes.obj_torch._properties = {
								name = "torch",
								longname = "An electric torch",
								desc = "A small portable electric torch, to help you see when it is dark"
							}
							
Simple, eh? :)

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.
So we must define the method 'twist':

	function classes.obj_torch:twist(info)
		
	end

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.

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.

	function classes.obj_torch:twist(info)
		if self._properties.state == "lit" then self._properties.state == "unlit" -- if it is lit, make it unlit
		else self._properties.state == "lit" end -- Otherwise, make it lit
	end

Very good, but we must show everyone in the room what is going on:

	function classes.obj_torch:twist(info)
		if self._properties.state == "lit" then 
			self._properties.state == "unlit" -- if it is lit, make it unlit
			self._properties.desc = "A small portable electric torch, to help you see when it is dark. It is not lit."
			info.person:_say("/me turns off the torch")
		else
			self._properties.state == "lit" -- Otherwise, make it lit
			self._properties.desc = "A small portable electric torch, to help you see when it is dark. It is lit."
			info.person:_say("/me lights the torch")
		end 
	end

As you can see, the colon ':' is used to call methods, or functions of another object. Remember that people are objects too!
The default 'look' method uses the 'desc' property, so we have changed it, to show whether the torch is lit or not.

It's done!

More to come, including creating new rooms :)

Files

AUTHORS0 B
COPYING0 B
ChangeLog8.3 KiB
INSTALL0 B
MUD files223 B
README2.1 KiB
TODO1.5 KiB
bot.lua7.1 KiB
classes.lua288 B
commands.lua7.2 KiB
common.lua2.6 KiB
containertables.inc.lua1.4 KiB
def_object.lua2.0 KiB
def_occupant.lua2.3 KiB
def_room.lua2.6 KiB
editing.lua1.4 KiB
luacomponent2.5 MiBbinary
luacomponent.cpp9.0 KiB
mt_object.lua102 B
muc.lua7.1 KiB
objects/obj_banner.lua611 B
objects/obj_bar.lua441 B
objects/obj_box.lua227 B
objects/obj_cat.lua892 B
objects/obj_container.lua349 B
objects/obj_cupboard.lua203 B
objects/obj_d2door.lua0 B
objects/obj_door.lua601 B
objects/obj_drinking_tables.lua396 B
objects/obj_drinks.lua404 B
objects/obj_fireplace.lua738 B
objects/obj_kitten.lua188 B
objects/obj_oven.lua723 B
objects/obj_small_chair.lua686 B
objects/obj_toaster.lua231 B
objects/obj_window.lua1020 B
readme2.1 KiB
rooms/d2.lua748 B
rooms/kitchen.lua469 B
rooms/lounge.lua1019 B
rooms.lua82 B
soo.lua2.4 KiB
svn-commit.tmp138 B