Synonyms to built-in commands

Hello! I am trying to implement a grab verb/command (or really just synonyms to built-in verbs), in this case, a synonym for take. However, I can't figure out how to implement it with all of the same functionality as take, such as if the object is in the same room as the player and if it is in an open container then it should also be possible to grab it. I would like to pass the parameters of grab to take and let the existing take scripts do the work. something like

<command>
    <pattern>grab #object#</pattern>
    <script>
      take object
    </script>
</command>

Thank you so much!


There's a few ways to do this.

In general, you can run another command by doing something like:

HandleSingleCommand ("take ball")

However, if there are multiple balls in the room, that would present a disambiguation menu just as if the player typed it.
To specify a particular item, you could use the 'metadata' parameter to HandleCommand. For example:

command = "take " + GetDisplayAlias (object)
metadata = NewStringDictionary()
dictionary add (metadata, GetDisplayAlias (object), object.name)
HandleCommand (command, metadata)

However, this is quite inefficient. It makes the engine go through all the work of deciding which command you want to use. So in most cases, you can run the script associated with one of the core commands. For example:

params = NewObjectDictionary()
dictionary add (params, "object", object)
do (take, "script", params)

Or in this case, you could look at the code of the core "take" command, and see how it works. In this case, it would be:

DoTake (object)

because the 'take' command has a function to process all of its built-in stuff.

Or, if you're only interested in creating a synonym, then you could just change the pattern of the existing command.
In your start script, you could just do:

take.pattern = "^(take|get|pick up|grab) (?<object>.*?)$"

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

Support

Forums