Functions: Difference between revisions
From Iron Realms Nexus Client Documentation
No edit summary |
|||
(21 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
Functions and scripts | <table> | ||
<div class="row"> | |||
<div class="large-8 columns"> | |||
Functions and scripts represent the pinnacle of what the Nexus client can provide in terms of power and customization, albeit with higher complexity. These functionalities are programmed using [[Javascript]], a versatile and widely-used language. | |||
In this section, we will not delve into the details of coding in [[Javascript]]. However, we will introduce you to some of the built-in functions and guide you through creating your own custom code. This will empower you to enhance and refine your skill set for more intricate and responsive interactions. | |||
== Scripts vs. Functions == | ==== 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. | * 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 | * Functions are reusable code blocks that can be called from scripts or directly from the client's input. | ||
== Calling functions == | ==== 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. | 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 == | ==== 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 [ | 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 [[3.0_Simplified_Scripting|Simplified Scripting]] 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] ...''' | * 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. | * 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 ==== | ||
=== Commands === | |||
===== 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. | * '''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 === | * '''display_notice(text, fgcolor, bgcolor)''' - display a notice on the output screen. | ||
===== Variables ===== | |||
* '''get_variable(name)''' - Retrieve the value of a variable from the client's simplified scripting system. | * '''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. | * '''set_variable(name, val)''' - Set a variable for the client's simplified scripting system. | ||
Line 26: | Line 32: | ||
* '''mul_variable(name, by)''' - Multiply 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. | * '''div_variable(name, by)''' - Divide a variable from the client's simplified scripting system. | ||
=== Reflex Manipulation === | |||
===== Reflex Manipulation ===== | |||
* '''reflex_find_by_name(type, name, case_sensitive, enabled_only, package))''' - Search for a specific reflex. | * '''reflex_find_by_name(type, name, case_sensitive, enabled_only, package))''' - Search for a specific reflex. | ||
* '''reflex_enable( | ** ''type'' - Type of reflex: 'alias', 'trigger', 'keybind', ... | ||
* '''reflex_disable( | ** ''name'' - Name to search for | ||
=== Output Manipulation (Trigger Scripts)=== | ** ''case_sensitive'' - Whether the name needs to match case exactly | ||
* ''' | ** ''enabled_only'' - Set if disabled reflexes (including reflexes in disabled groups) should be ignored | ||
* ''' | ** ''package'' - Name if a package to search in; omit if searching in the main list | ||
* ''' | * '''reflex_enable(reflex)''' - Enable a reflex (reflex is as returned by reflex_find_by_name above). | ||
* ''' | * '''reflex_disable(reflex)''' - Enable a reflex (reflex is as returned by reflex_find_by_name above). | ||
''' | |||
=== Misc. === | ===== Output Manipulation (Trigger Scripts)===== | ||
* '''current_text()''' - An unformatted version of the line that fired the trigger. | |||
* '''gag_current_line()''' - Hide the line that fired the trigger from the output window. | |||
* '''colorize_current_line(start, length, fgcolor, bgcolor)''' - Colorize/highlight a specified part of the line that fired the trigger. | |||
* '''replace_current_line(start, length, newtext, fgcolor, bgcolor)''' - Replace a party of the current line with the specified text and color. | |||
===== UI Manipulation ===== | |||
* '''client.register_custom_tab(tab,container_id)''' - Make a custom UI tab. ''Please note, this is unsupported.'' | |||
===== Tab Display ===== | |||
* '''set_custom_tab_html("tab_name", "html")''' - Display output in a tab. | |||
* '''append_custom_tab_html("tab_name", "html")''' - Display output in a tab. | |||
===== Buttons ===== | |||
* '''buttons_set_label(id, text)''' - Set the text label on a button. | |||
* '''buttons_set_commands(id, cmds)''' - Sets the command sent to the game when the button is pressed. | |||
* '''buttons_set_highlight(id, on_off)''' - Set whether the button is highlighted or not. | |||
* '''buttons_set_default(id)''' - Reset a button to the default value. | |||
===== Misc. ===== | |||
* '''to_number(val)''' - Convert a string number to a value. | * '''to_number(val)''' - Convert a string number to a value. | ||
* '''send_GMCP(message, arguments)''' - Sends a GMCP message to the game. Arguments are an object or string, depending on the GMCP call used - see the GMCP documentation for more information. | |||
== Default functions == | ==== Default functions ==== | ||
There are three functions which are called automatically by the client. These are '''onLoad''', called when the settings are loaded, '''onGMCP''', called upon receiving a GMCP message, and '''onBlock''', called upon receiving each text block, allowing you to perform 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 are loaded, '''onGMCP''', called upon receiving a GMCP message, and '''onBlock''', called upon receiving each text block, allowing you to perform manipulations on it, or kickstart functionality that you want to execute on every prompt. | ||
The function does not receive any data. | The function does not receive any data. | ||
Line 47: | Line 73: | ||
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. | ||
*Nexus 3 uses nexusclient.current_block instead of current_block | |||
== Examples == | ==== Examples ==== | ||
[[ | For some examples of functions, read the [[3.0_Examples|examples]] page. | ||
</div> | |||
<div class="large-4 columns"> | |||
{{Nexus_3_Sidebar}} | |||
</div> | |||
</div> | |||
</table> |
Latest revision as of 02:14, 21 June 2023
Functions and scripts represent the pinnacle of what the Nexus client can provide in terms of power and customization, albeit with higher complexity. These functionalities are programmed using Javascript, a versatile and widely-used language.
In this section, we will not delve into the details of coding in Javascript. However, we will introduce you to some of the built-in functions and guide you through creating your own custom code. This will empower you to enhance and refine your skill set for more intricate and responsive interactions.
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 reusable 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 Simplified Scripting 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.
- display_notice(text, fgcolor, bgcolor) - display a notice on the output screen.
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.
- type - Type of reflex: 'alias', 'trigger', 'keybind', ...
- name - Name to search for
- case_sensitive - Whether the name needs to match case exactly
- enabled_only - Set if disabled reflexes (including reflexes in disabled groups) should be ignored
- package - Name if a package to search in; omit if searching in the main list
- reflex_enable(reflex) - Enable a reflex (reflex is as returned by reflex_find_by_name above).
- reflex_disable(reflex) - Enable a reflex (reflex is as returned by reflex_find_by_name above).
Output Manipulation (Trigger Scripts)
- current_text() - An unformatted version of the line that fired the trigger.
- gag_current_line() - Hide the line that fired the trigger from the output window.
- colorize_current_line(start, length, fgcolor, bgcolor) - Colorize/highlight a specified part of the line that fired the trigger.
- replace_current_line(start, length, newtext, fgcolor, bgcolor) - Replace a party of the current line with the specified text and color.
UI Manipulation
- client.register_custom_tab(tab,container_id) - Make a custom UI tab. Please note, this is unsupported.
Tab Display
- set_custom_tab_html("tab_name", "html") - Display output in a tab.
- append_custom_tab_html("tab_name", "html") - Display output in a tab.
Buttons
- buttons_set_label(id, text) - Set the text label on a button.
- buttons_set_commands(id, cmds) - Sets the command sent to the game when the button is pressed.
- buttons_set_highlight(id, on_off) - Set whether the button is highlighted or not.
- buttons_set_default(id) - Reset a button to the default value.
Misc.
- to_number(val) - Convert a string number to a value.
- send_GMCP(message, arguments) - Sends a GMCP message to the game. Arguments are an object or string, depending on the GMCP call used - see the GMCP documentation for more information.
Default functions
There are three functions which are called automatically by the client. These are onLoad, called when the settings are loaded, onGMCP, called upon receiving a GMCP message, and onBlock, called upon receiving each text block, allowing you to perform 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.
- Nexus 3 uses nexusclient.current_block instead of current_block
Examples
For some examples of functions, read the examples page.
Important Links
Nexus 3.0 Documentation
The following links describe how to use the Nexus Client.
The Basics
- Nexus Account
- Game Selection
- Character Management
- The Game Client
- Windows and Tabs
- Keys, Gauges, Avatars
- General Functions
Client Settings
- Display Options
- Colors
- Buttons
- Reflex Packages
- Reflexes
- Variables
- Custom Tabs
- Gauges
- Advanced
- Feedback
- Help