Skip to content

Functions

Kristof Kovacs edited this page Mar 4, 2023 · 6 revisions

Artemis Functions - The Great User Handbook

This page will discuss every quirk of how functions work in Artemis. For information about the technical structure of functions, refer to the class and package structure page.

Description - What are functions?

Functions are a way to access any data parsed by Artemis in two forms: You can place it on your HUD, using info boxes or access them by running /function and it's subcommands.

Types of Functions

We have two main types of functions at the moment:

  • Normal: Returns game (and system) related data (eg. XP, LEVEL)
  • Generic: These functions always have arguments which are then used to calculate new data (eg. ADD, FORMAT, EQUALS)

Function Usage - How do I use functions?

To display a function on your HUD, use info boxes: Set the selected info box's content to a string containing an expression context (more on this below), and you are good to go.

To calculate a function value with commands: Use /function test <string>.

Example

To display a simple info, like your current speed, use:

  • {bps} in an info box
  • /function test {bps}

Function Syntax - How do I format functions?

Function syntax slightly differs for functions with and without argument.

For functions to be evaluated, you need to be in a expression context. Otherwise, functions will be ignored, and will display as text.

Not expression context {EXPRESSION_CONTEXT_CALL_FUNCTIONS_HERE} Not expression context

Example

To mix functions and strings together, follow the below example:

My speed is: {bps} m/s

This string will evaluate into My speed is 12 m/s, depending on your current speed.

Function Argument Syntax

A function can have arguments. These are either optional or required. Argument order is important, and cannot be switched up. If a function's arguments are optional, but you want to change one, you need to treat all other arguments like they are required.

A functions arguments can either be:

  • Another function's return value
  • A constant expression

Constant Expressions

There are four types of constants:

  • String -> Must be wrapped in ": "string"
  • Integer -> 12
  • Double (number with decimals) -> 12.1
  • Boolean (true or false) -> true

To use a constant expression, simply put it in a function's argument or in an expression context.

Functions without arguments

Functions without any arguments (either no argument supplied, or function does not have any arguments) can be called like:

FUNCTION_NAME
FUNCTION_NAME()
Example
My speed is: {bps}
My speed is: {bps()}

Functions with arguments

Functions with arguments need to be called like:

FUNCTION_NAME(arg1; arg2; ...; argN)

Each function argument has a type, which needs to match to the supplied argument. If a function does not require arguments, but there are optional ones, you either specify none (and follow the no argument syntax), or all.

The function argument delimiter is a semi-colon (;).

You can use functions as arguments for functions:

ROUND(FUNCTION_RETURNING_NUMBER; 2)

Explanation

  • ROUND -> Round a number to the specified decimal places.
  • FUNCTION_RETURNING_NUMBER -> A function returning a number
  • 2 -> Second argument, specifying the wanted decimal places.

Numerical Function Formatting

Functions returning a number have special formatting options. If you apply these to any other types of functions, nothing will happen. The numerical function formatting is a suffix to the function call itself.

There are two types of formatting flags:

  • F - The number is gonna get a localized format, adding decimal separators, according to your locale.
  • <number> - Number of decimal places to display. The default value for this is 2.

Usage

To format a number, and display 3 decimal places, the suffix would be :F3. Note that you cannot switch the order up, :3F will not work. Only limiting decimal places is possible too, with :2. Only formatting is possible with :F.

FUNCTION_RETURNING_NUMBER:F3
FUNCTION_RETURNING_NUMBER:F
FUNCTION_RETURNING_NUMBER:3
FUNCTION_RETURNING_NUMBER_WITH_ARGUMENTS("argument"; 12):F2

Function Escaping, Coloring and Special Cases - How do I put colors/special characters into function outputs?

Coloring

Strings submitted for function calculation (from now on, templates) are escaped and colored before calculating the function values itself. To color the output, you can use Minecraft's coloring system, with a small change: You can use & instead of the weird symbol Minecraft uses (§).

Example

&5Mythic Dry Count: {dry_count}

Newlines

You can use \n to add a line break into a template. Adding \n will reset the color and format of the new line.

Escaping

If you tried to put a { or } in your template, and want it to display it as a string, you likely got an error. To solve this, you can escape any character with prefixing it with \ (which would mean using \{). Similarly, if you want a real & sign, instead of a formatting code, use \&.

Special Escape Cases

There are a list of characters, where escaping will alter their value to some other character:

  • \E -> Emerald Symbol in Wynncraft
  • \B -> Emerald Block Symbol in Wynncraft
  • \L -> Liquid Emerald Symbol in Wynncraft
  • \H -> Health Symbol in Wynncraft
  • \M -> Mana Symbol in Wynncraft
Clone this wiki locally