Template ‐ READABLE - ThePix/QuestJS GitHub Wiki
Okay, let me be honest here, this template does not do much. It does flag an item as "readable", but nothing in Quest 6 actually checks for that. It also sets the icon and will add "read" to the list of verbs (but only when held if the template passed true
).
All the real work you need to do yourself. The reason for that is that there are a lot of ways you might want to do that. Let us look at a few examples.
The first is a simple newspaper. The "read" attribute is just a string.
createItem("old_newspaper", TAKEABLE(), READABLE(), {
examine:'A newspaper from the eighties; yellow with age.',
read:'You spend a few minutes reading about what happens on the day 14th June 1987 (or perhaps the day before). A somewhat mocking article about an archaeologist, Dr Ruudhorn, and Atlantis catches your eye.',
loc:'basement',
})
Here is a book. It has to be held to be read (so READABLE is sent true
). The work is done in the "read" function, which first checks the book is held, and if it is, prints a message. In this case, not very helpful...
createItem("book", TAKEABLE(), READABLE(true), {
loc:"lounge",
examine:"A leather-bound book.",
read:function(isMultiple, char) {
if (options.char.name !== this.loc) {
return falsemsg('{nv:char:do:true} not have {ob:item}.', options)
}
msg (prefix(this, isMultiple) + "It is not in a language " + lang.pronounVerb(char, "understand") + ".")
return true
},
})
In the third example, the book example has been expanded; you can now hand the book to Lara, a rabbit, who can read it (it makes sense in context).
createItem("book", TAKEABLE(), READABLE(true), {
loc:"lounge",
examine:"A leather-bound book.",
read:function(isMultiple, char) {
if (options.char.name !== this.loc) {
return falsemsg('{nv:char:do:true} not have {ob:item}.', options)
}
if (char === w.Lara) {
msg ("'Okay.' Lara spends a few minutes reading the book.")
msg ("'I meant, read it to me.'")
msg ("'All of it?'")
msg ("'Quick summary.'")
msg ("'It is all about carrots. The basic gist is that all carrots should be given to me.' You are not entirely sure you believe her.")
}
else {
msg (prefix(this, isMultiple) + "It is not in a language " + lang.pronounVerb(char, "understand") + ".")
}
return true
},
})
The last example is a box. I want this to have the icon for a container when listed in the item pane, so I need that template to be after READABLE. The text is on the lid, and the player might do READ BOX or READ LID, so I have added a regex to allow the box to be referred to either way. Once the label has been read the box can be opened, and I have used the LOCKED_WITH template to do that.
createItem("box", READABLE(), CONTAINER(true), LOCKED_WITH([]), {
examine:"It is large, wooden box. There is a label on the lid.",
regex:/crate|label|lid/,
read:function() {
msg('The label says: "The Hat and Crowbar Company - exchanging hats for crowbars since 2020."')
this.locked = false
},
})