Python Universe Builder
Creating Objects from Existing Classes
This is pretty easy. The general form is:
objid = Classname("main name,synonym1,synonym2")
objid.property = value
objid.property2 = value
Broken down into parts, we have
- objid - some identifier, unique within the file. This can
be any valid Python variable name, but the standard form is to begin with a
lowercase letter. Examples: rock, coat, greenSlime, furryHairBall.
- Classname - the name of a previously defined object class.
Unless it's defined in the same file, you'll have to prefix it with the name
of the file where it is defined. Examples: pubobjs.Thing, pubobjs.NPC,
- name and synonyms - in the parenthesis, put a string
containing the object's main name and any number of synonyms, separated by
commas. Example: "rock,stone,large pebble,large,small boulder,small". Note
that whenever you have a multiword name or synonym, the first word of the name
must also be given by itself.
- property - this is the name of a valid property for the
object class. This may be found by directly examining the source code (they're
commented), or (eventually) in the library reference.
Examples: light, size, isOpen.
- value - you can assign any Python value to any property,
but their meaning varies. A property like "light" generally expects a number
between 0 and 100; boolean values like "isOpen" expect TRUE or FALSE, and string
properties like "desc" expect a string in quotes.
# create a room
northend = Room("North End of Town")
northend.desc = "Standing at the north end of the town, you have shops on \
three sides and the center of town to the south."
# create some objects (they go into the most recently created room)
barrel = pubobjs.Container("barrel,keg")
barrel.desc = "A large wooden barrel has been set at the end of the street."
barrel.canContainLiquid = TRUE
barrel.size = 30
water = pubobjs.Liquid("water,H2O")
water.size = 5
water.MoveTo(barrel) # place the water inside the barrel
. . . . . . Joe Strout
. . . email@example.com