Capturing a command

Post Reply
Skriptz
Posts: 45
Joined: Sun Dec 27, 2009 10:48 pm

Capturing a command

Post by Skriptz »

How do you capture a command and put it into a variable?
What I want to do is have a variable that will capture the last command and then keep updating with the next command entered and have it send when a trigger calls for it.

For example I have stupidity and I type the command "outr goldenseal" but I get "You moon the world." instead. So with the moon the world as a trigger to send(VarLastCommand) so that way I will be able to get that goldenseal out.

Iocun
Posts: 174
Joined: Wed Dec 02, 2009 1:45 am

Re: Capturing a command

Post by Iocun »

The predefined variable "command" already does what you are asking for. "Command" always holds the last command you entered. So you could have the trigger on "You moon the world." simply execute: send(command).

This will however only work if you entered said command manually. The command variable doesn't hold things you have sent to the mud with send(), for instance. If you want those to be captured as well, you'll have to update "command" yourself (e.g. by doing command="outr goldenseal" after your send("outr goldenseal")), or write those commands in another variable.

P.S. Just for the sake of completeness: If you had to find your own way of capturing commands and "command" didn't already exist, the easiest way might be to create an alias with the pattern ^(.+)$, which would fire on anything you typed at all. Then you could store matches[2] in your variable. The main difficulty then would be to decide whether to still send() that command to the mud, or not: If it's a command directly meant for the mud, you'd want it to be sent through with send(). If it's however another alias you entered, you wouldn't want this, as it would be an incomprehensible command for your mud. So you'd have to check first whether the entered command already fits another alias or not. Clearly, just using "command" makes all this much simpler!

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Capturing a command

Post by Vadi »

send() does bypass the command because it bypasses the alias matching altogether. expandAlias doesn't though and should act as user input, so it should fill up the command variable.

Post Reply