I'm trying to find a way to add an synonym

In my adventure when the player open or reads a certain book a key falls out of the book
I have a script for the verb read but need to have "open" as an alternative word so the the same script is run if the player types "read book" or "open book".
The only way I've found to do this is to make the book an openable/closed object but I feel there must be a better way to do this.

For example if I wanted to add the synonyms 'polish' and 'rub' to the verb 'clean' for the object 'oil lamp' and have the same script running, how would I do this?
Maybe Quest is different than other text adventure creators I've used and I need to use functions instead and call the same function for each synonym used on an object.


For the polish/rub/clean example, I believe it's possible in the desktop editor. You can open the verb and change its pattern. I think that verbs appear in the object tree to the left just like custom commands do, but there might be something you have to do to show it.
The attribute you want to change is called pattern. For example, the built in "wear" verb has the pattern put #object# on; wear; put on; don; wear.

I could be wrong about some of that; the web editor doesn't show verbs in the editor, so it's harder to do for me.


However, as far as making open and read the same, it's a bit less simple. This is because "open" is a built-in command, and so Quest won't let you use it as a verb.
(verbs have a script for each object they can be used on; commands have a script as part of the command. If two commands match what the player typed, the rules to determine which one happens are complex, but commands normally beat verbs)

You don't need to write the script out twice, because it's already there. A verb is saved as a script attribute on the object.
So if you have a "read" verb, the object probably has an attribute named read which contains the script. You can run that script yourself. (The attribute name is normally the same as the verb, but not always. If in doubt, you can look on the object's Attributes tab for it, or look at the verb to see what its "property" is)

So, if you make the book openable using the core command, you could give it the following script for its "When object is opened" script:

this.isopen = false
do (this, "read")

The first line closes it again, so that attempting to open a book twice won't say "It's already open". And the second like tells it to run the script attribute named 'read'.

(and in case you haven't come across it yet, any time a script is run using do, it sets a special variable this to be the current object. So in verbs or in most of the other scripts which you can edit in an object's tabs, you can use this as a shorthand for the name of the object)


Thanks mrangel, I'll try what you have suggested.


This topic is now closed. Topics are closed after 60 days of inactivity.

Support

Forums