Tutorial 4 ‐ Templates - ThePix/QuestJS GitHub Wiki
... Continued from Items.
Templates are how we give items a set of attributes. They work like types in Quest 5 - and are nothing like templates in Quest 5!
JavaScript is an object-orientated language (though its use of prototypes is very unusual), and if you are familiar with it you might be wondering why we do not use JavaScript classes; we could create a class for each type, and have sub-classes, etc. This turns out to be a bit clumsy when it comes to setting attributes. We would send out custom attributes to the constructor, which would then pass them to the super constructor. And then it would overwrite the attributes itself. There is also no multiple inheritance. These are by no means insurmountable, but templates seems to offer a simpler way forward._
A template can either be a dictionary or a function that returns a dictionary. The advantage of a function is that it can extend an existing templates and can take parameters.
DEFAULT_ROOM
This is added automatically when you use createRoom
.
DEFAULT_ITEM
This is added automatically when you use createItem
.
TAKEABLE()
Add this to an item to allow it to be picked up.
WEARABLE(layer, slots)
Add this to have an item takeable and wearable. Quest 6 uses the same concept of layers and slots as Quest 5. The layer should be a number, and might be 1 for underwear, 2 for shirt and trousers and 3 for a coat. Slots should be an array of body locations that the item covers. A character can only wear one item in a slot in each layer, and cannot wear or remove items in lower layers in a slot if wearing a garment at a higher layer in the same slot (so could not take off a shirt whilst wearing a coat).
You can alternatively just use WEARABLE()
(i.e., without any parameters) to ignore the system altogether.
CONTAINER(openable)
Add this to make a container. The parameter will determine if the container can be opened and closed. If it is openable, then by default the container will be closed (set closed:false
in the attributes otherwise). If the item can be taken, include TAKEABLE before this.
SURFACE()
This allows the player to place things on top of the item.
SWITCHABLE(alreadyOn)
Add this to make a switchable item. The parameter will determine if the item is on at the start of the game. If the item can be taken, include TAKEABLE before this.
COMPONENT(nameOfWhole)
Use this to create a component of something bigger (the name of which should be provided).
PLAYER()
For the player object.
NPC()
For other characters.
Others
Other templates are available, but are a bit more complicated. Templates are discussed more on their own pages, but for now the important thing is that you are aware they exist.
- Takeable
- Container and surface
- Openable, locked with, locked door, key
- Wearable
- Furniture
- Switchable
- Edible
- Components
- Countable
- Zone
- Merchandise (including how to create a shop)
- Shiftable (can be pushed from one room to another)
- Transit system (lifts/elevators, buses, trains, simple vehicles)
- NPC
- TOPIC
You can also create your own templates.
Continues in Items and rooms again...