Functions: Difference between revisions
From Iron Realms Nexus Client Documentation
No edit summary |
No edit summary |
||
Line 12: | Line 12: | ||
== Variables == | == Variables == | ||
Scripts and functions are generally self-contained, variables are local to the code block and are cleared when the script or function finishes. To interact with variables used in the [SimplifiedScripting] system, you'll want to use the built-in modules: get_variable, set_variable etc. | Scripts and functions are generally self-contained, variables are local to the code block and are cleared when the script or function finishes. To interact with variables used in the [SimplifiedScripting] system, you'll want to use the built-in modules: get_variable, set_variable etc. | ||
* Functions called in a trigger receive information about the match: '''args.text, args.match, args.prefix, args.suffix, args.backrefs[1] ...''' | |||
* Scripts receive the backrefs ('''args[0]., args[1],. args[2], ...''') and the current_package variable indicating the active package. | |||
== Built-in modules == | == Built-in modules == | ||
Line 36: | Line 38: | ||
* '''to_number(val)''' - Convert a string number to a value. | * '''to_number(val)''' - Convert a string number to a value. | ||
== Default functions == | |||
There are three functions which are called automatically by the client. These are onLoad, called when the settings areloaded, onGMCP, called upon receiving a GMCP message, and onBlock, called upon receiving each text block, allowing you to peform manipulations on it, or kickstart functionality that you want to execute on every prompt. | There are three functions which are called automatically by the client. These are onLoad, called when the settings areloaded, onGMCP, called upon receiving a GMCP message, and onBlock, called upon receiving each text block, allowing you to peform manipulations on it, or kickstart functionality that you want to execute on every prompt. | ||
Line 74: | Line 49: | ||
The onBlock function can make use of the current_block variable, which holds the individual lines (current_block[0] is the first one, current_block[1] is the second one, and so on). The manipulation methods described with triggers are all applicable on these as well. | The onBlock function can make use of the current_block variable, which holds the individual lines (current_block[0] is the first one, current_block[1] is the second one, and so on). The manipulation methods described with triggers are all applicable on these as well. | ||
== Examples == | |||
[[GMCP Data|GMCPData]]: This example reads some data coming over via [[GMCP]] and assigns it to variables. | [[GMCP Data|GMCPData]]: This example reads some data coming over via [[GMCP]] and assigns it to variables. |
Revision as of 23:25, 15 February 2016
Functions and scripts are the most powerful option that the client has to offer, but also one that is most difficult to use. Functions and scripts are programmed in the Javascript language.
While we won't be covering how to code in JavaScript in this section, we'll cover some of the built-in functions and how to build your own custom code to further expand your reflexes.
Scripts vs. Functions
- Scripts are specific code blocks that are fired as a result of a reflex being fired. This can be a trigger, alias, or keybind.
- Functions are re-usable code blocks that can be called from scripts or directly from the client's input.
Calling functions
Functions can be called from scripts by using run_function(name, args, package). As mentioned above, they can also be called directly from the client's input, so you'll want to make sure your functions are named in such a way that they do not overlap with in-game commands you may wish to use.
Variables
Scripts and functions are generally self-contained, variables are local to the code block and are cleared when the script or function finishes. To interact with variables used in the [SimplifiedScripting] system, you'll want to use the built-in modules: get_variable, set_variable etc.
- Functions called in a trigger receive information about the match: args.text, args.match, args.prefix, args.suffix, args.backrefs[1] ...
- Scripts receive the backrefs (args[0]., args[1],. args[2], ...) and the current_package variable indicating the active package.
Built-in modules
Commands
- send_command(input, no_expansion) - Send a command to the game. Set no_expansion to 1 to send the exact string to the game without expansion.
Variables
- get_variable(name) - Retrieve the value of a variable from the client's simplified scripting system.
- set_variable(name, val) - Set a variable for the client's simplified scripting system.
- delete_variable(name) - Delete a variable from the client's simplified scripting system.
- inc_variable(name, by) - Increment a variable from the client's simplified scripting system.
- dec_variable(name, by) - Decrement a variable from the client's simplified scripting system.
- mul_variable(name, by) - Multiply a variable from the client's simplified scripting system.
- div_variable(name, by) - Divide a variable from the client's simplified scripting system.
Reflex Manipulation
- reflex_find_by_name(type, name, case_sensitive, enabled_only, package)) - Search for a specific reflex.
- reflex_enable(id) - Enable a reflex (id returned by reflex_find_by_name above).
- reflex_disable(id) - Enable a reflex (id returned by reflex_find_by_name above).
Output Manipulation (Trigger Scripts)
- current_line.parsed_line.text() - An unformatted version of the line that fired the trigger.
- current_line.parsed_line.gag - Gag the line that fired the trigger from the output window.
- current_line.parsed_line.colorize(startchar, endchar, fgcolor, bgcolor) - Highlight/color part/all of the line that fired the trigger.
- current_line.parsed_line.replace(startchar, endchar, replacementtext, fgcolor, bgcolor) - Replace part/all of the line that fired the trigger.
Misc.
- to_number(val) - Convert a string number to a value.
Default functions
There are three functions which are called automatically by the client. These are onLoad, called when the settings areloaded, onGMCP, called upon receiving a GMCP message, and onBlock, called upon receiving each text block, allowing you to peform manipulations on it, or kickstart functionality that you want to execute on every prompt. The function does not receive any data.
The onGMCP function receives two arguments - args.gmcp_method is the GMCP message name, args.gmcp_args are the parameters (if any).
The onBlock function can make use of the current_block variable, which holds the individual lines (current_block[0] is the first one, current_block[1] is the second one, and so on). The manipulation methods described with triggers are all applicable on these as well.
Examples
GMCPData: This example reads some data coming over via GMCP and assigns it to variables.