Explanation:
Args are the arguments that are passed when one gives a command (so basically everything you ever enter into the console, that's fair game for args). This is done by taking a command, like 'kill stinky pete', cutting it up into pieces in the background, and having it stored for the user to use in their javascript code in their alias as usable strings.
The important part about args is that you can select all or some of the text that was passed along with the alias depending on the index of args that you are looking it. For our example of 'kill stinky pete', args would have five indexes: 0, 1, 2, $*, and *. If you were to programmatically retrieve them, it would look like this: kill stinky pete, stinky, pete, stinky pete, stinky pete. The ones we care about are going to be the non-zero numbers and *. The non-zero numbers inform us that at least one other word was passed along with our alias. The asterisk will allow us to retrieve all information that was passed other than the alias.
In a nice graph format:
Index | Output
0 | kill stinky pete
1 | stinky
2 | pete
$* | stinky pete
* | stinky pete
In use:
So, lets say that you want to automate killing crap. The command for doing so is "kill <identifier for what to kill>". So it would be a good idea to create an alias "kill", and then use some fancy javascript to remember what you last attacked. That way, when your "You killed" trigger pops, you can have it try to kill the same thing again in the hopes that there's another enemy standing around. To do that, we're going to need to use what was supplied with the "kill" command and store it to a variable. That'd look something like this:
alias: kill
Code: Select all
if (args[1] !== undefined){
gwc.userdata.last_target = args['*'];
gwc.connection.send( 'kill ' + args['*'] );
}
else{
gwc.output.append('Kill what?');
gwc.output.color('red');
}
Our trigger would then look something like this:
trigger: You killed
Code: Select all
gwc.connection.send( 'kill ' + gwc.userdata.last_target );
Advanced args use: (Using non-capturing groups in regular expressions)
Once you get the hang of taking chunks of text out of a sentence using regular expressions, you may feel like it is time to simplify your trigger list by putting multiple triggers together that all perform the same types of actions. This can be done normally using (?:<statement one>|<statement two>). When one wishes to receive a portion of the statements within the non-capturing group, then the indexing for args becomes different. Instead of having each numerical index in args being a portion of the received text, it instead returns what each portion of the non-capturing group collected when the trigger fired. This means that, if you have four different statements, you will have three that are undefined and a forth one that is defined (and contains the text that you want).
To give an example, if you were trying to put all of your statements together that were for a quest in which there were several statements that all used different language to describe the same thing, you may be tempted to put them together into a non-capturing group that had capturing groups inside of it.
Example of regular expression:
(?:The (.*) throws a rock!|The (.*) bites you|The (.*) goes berserk)
We know that, because there are three different statements within our non-capturing group, there will be three different non-zero integer indexes for args: 1, 2, and 3. Each of these will correlate with the individual statements. So, if you wanted the first statement, you would use args[1] and so forth. What if you wanted to get whichever one is available though?
Then you'd use something like this in order to get the one defined value:
Code: Select all
for (var i = 1; i < 5; i++){
if ( args[ i ] !== undefined ){
var value = args[ i ];
break;
}
}
//Here is where you'd use the value variable
Why that's awesome:
Aliases are amazing. They have a great amount of power, but aliases that can have extra information passed with them are even more awesome. Don't take my word for it, look at script examples like the one that allows you to save statistical information about forgings and retrieve specific stats by an alias call. Literally, the sky is the limit.