Command calling command

Is there a way for a command to call another command? Basically have the command force a player input?


You mean how do you make a command run an endless loop until the player inputs a proper response?

You script get input into a function. If the result is improper, call the same function again at the end of that very function.


No. I want one command to call another command. I have a command called "spend xp" that explains how to spend your xp to learn new skills. the command to do that is LEARN

LEARN ?
msg ("This command allows you to learn new skills as long as you have the experience to spend.")
command (spend xp)


There's a couple of ways you could do it. The simplest is probably calling HandleCommand, which will do everything including echoing the command as if the player typed it (if echo is turned on).

Note that the behaviour of turnscripts could be a little unpredictable when you do this.

For example:

HandleCommand ("go north", null)

If you want to make things a little easier for the parser and ensure that it doesn't get confused, you can use a dictionary to identify the objects referenced in the command. In this case, you use strings containing the object as it is typed in the command, and a string containing the actual name of the object. For example:

params = NewStringDictionary()
dictionary add (params, "north", "exit27")
HandleCommand ("go north", params)

This will prevent the disambiguation menu popping up if they're in a room with more than one north exit. Though this technique is probably more useful in the case of inventory objects, in case they're still carrying an object from earlier in the game that has a similar name.


Simpler option: if you want to run a single command that doesn't have any parameters. For example, if you wanted to display the player's inventory you could use:

do (inventory, "script")

Note that this uses the name of the command, not its pattern. And it doesn't echo the command to the screen, clear the screen before the command, or run turnscripts after the command.


Awesome! Just what I was looking for. Thanks!


LEARN ?
msg ("This command allows you to learn new skills as long as you have the experience to spend.")
// command (spend xp)
// if spend xp is a command, make it a function and call it like:
spend xp()

I assume that the player can "spend xp" directly without using "learn"...


Log in to post a reply.

Support

Forums