Actions

Simple Scripting Conversion

From Iron Realms Nexus Client Documentation

Revision as of 02:24, 8 July 2023 by Argwin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The Nexus client includes two methods of creating [Reflexes], [Simplified Scripting], and [JavaScript]. While JavaScript allows you to create complex, sophisticated reflex packages, Simplified Scripting allows you to create reflexes without any knowledge of how to write code. However, the day may come when you're ready to make the jump from Simplified Scripting to JavaScript. This guide attempts to serve as a way to bridge that gap more easily.

Send Command

send_command(<command>);

Example:

send_command("put gold in pack");

Show Notice

display_notice(<text>, <fg color>, <bg color>[, <more text>, <fg>, <bg>, ...]);

Example:

display_notice("This will be colored blue.", "blue");

display_notice("This is black on a white background.", "black", "white");

display_notice("This will be red, ", "red", "", "while this is green, ", "green", "", "and this is orange on a blue background.", "orange", "blue");

Modify Variable

Variables are a bit more complicated, but we'll take it one step at a time...

Variable Scope

In Simplified Scripting, all variables basically have what's called Global Scope, meaning they can be used anywhere. In JavaScript variables can have different scope, so some are available anywhere (Global variables) and some can only be used in the specific block of code where they're defined (Local variables). Local variables are considered better because you cannot accidentally reference a variable in the wrong spot.

Local Variables

There are two kinds of local variables, constant and non-constant:

const myName = "Sarapis";

This declares a constant variable, one that won't change, and sets it to "Sarapis". The quotes tell us that the variable is a String, in other words it's text. To refer to this variable later you can use the variable name on its own, myName.

let myHealth = 2000;

This declares a non-constant variable and sets it to the number 2000. Because the value is a number and not text it doesn't need quotes. To change the variable later, you refer to the variable only and don't include 'let'. Note - you will only use the keyword 'let' when you declare the variable for the first time. If you use the keyword 'let' again after that you will re-declare the variable and erase any value that it holds.

Global/Session Variables

myArea = "New Thera";

This declares a non-constant variable with Global scope, so it can be used anywhere in your code. However, when you log off and close the browser or browser tab the variable will be deleted. Some people refer to these as Session variables, since they will only last during the current session.

Global/Nexus Variables

set_variable("myClass", "Jester");

If you want a variable to last beyond the current session, you have to save it as a Nexus variable. These are the variables that you can see in the Variables section of the settings. Actually, if you visit that Variables tab, you'll see that there are a lot of variables already created for you, and they're automatically updated too, like my_hp and my_mp.

let myHealth = get_variable("my_hp");

And this is how you access those variables when you need them. Note - If you try to get a variable that has not been set yet, you will see a bright red error and your script will not work.