Functions library

Within hash characters, you can define numerical calculations and string operations. In its simplest form, you can perform addition, subtraction, division, and multiplication. The plugin uses a functions library to assist with calculations, and that library offers many functions, listed below.

The function names on this page use capital letters, but the math library ignores case when it comes to function names.

Some examples:

  • {text:#MAX(@e_ccvalue, 64)#}
  • {text:#BITAND(@e_ccvalue, 63)#}
  • {text:#IF(@e_ccvalue > 64, "High", "Low")#}

Supported Operators

Operator

Description

Version

+

Additive operator / Unary plus / Concatenate string / Datetime addition

&

Concatenate string

Subtraction operator / Unary minus / Datetime subtraction

*

Multiplication operator, can be omitted in front of an open bracket

/

Division operator

%

Remainder operator (Modulo)

^

Power operator

Supported conditional statements

Conditional statement

Description

Version

IF(logical_condition, value_if_true, value_if_false)

Example:
IF(2>1,"Pass","Fail")

SWITCH(expression, val1,result1, [val2,result2], …, [default])

Example:
SWITCH(3+2,5,"Apple",7,"Mango",3,"Good","N/A")

Supported logical and math functions

Function

Description

Version

AND(logical1, [logical2], …

Determine if all conditions are TRUE

OR(logical1, [logical2], …)

Determine if any conditions in a test are TRUE


NOT(logical)

To confirm one value is not equal to another


XOR(logical1, [logical2], …)

Exclusive OR function


BOOL(number)

Convert a numerical value to boolean. 0=false, 1=true.

3.11-

SUM(number1, [number2],…)

Return sum of numbers supplied

AVERAGE(number1, [number2],…)

Return average of numbers supplied


MIN(number1, [number2],…)

Return the smallest value from the numbers supplied


MAX(number1, [number2],…)

Return the biggest value from the numbers supplied


RANGE(number, min, max)

Returs a value that is confined to the defined range.

3.11-

MOD(number, divisor)

Get remainder of two given numbers after division operator.


ROUND(number, num_digits)

ROUND(number, num_digits, rounding_mode)

Returns the rounded approximation of given number. Roundinig modes:

  • "awayfromzero" 
  • "toeven"  (default if none is specified)
  • "tozero" 
  • "up" 
  • "down"

rounding mode: 4.2-

FLOOR(number, significance)

Rounds a given number towards zero to the nearest multiple of a specified significance


CEILING(number, significance)

Rounds a given number away from zero, to the nearest multiple of a given number


POWER(number, power)

Returns the result of a number raised to a given power


RAND()

Produces a random number between 0 and 1


SIN(number)

Returns the trigonometric sine of the angle given in radians


SINH(number)

Returns the hyperbolic sine of a number


ASIN(number)

Returns the arc sine of an angle, in the range of -pi/2 through pi/2


COS(number)

Returns the trigonometric cos of the angle given in radians


COSH(number)

Returns the hyperbolic cos of a number


ACOS(number)

Returns the arc cosine of an angle, in the range of 0.0 through pi


TAN(number)

Returns the tangent of the angle given in radians


TANH(number)

Returns the hyperbolic tangent of a number


ATAN(number)

Returns the arc tangent of an angle given in radians


COT(number)

Returns the cotangent of an angle given in radians.


ATAN2(x_number, y_number)

Returns the arctangent from x- and y-coordinates


COTH(number)

Returns the hyperbolic cotangent of a number


ACOT(number)

Returns the inverse cotangent of a value, defined as acot(x) = atan(1/x).

3.11-

SQRT(number)

Returns the correctly rounded positive square root of given number


LN(number)

Returns the natural logarithm (base e) of given number


EXP(number)

Returns e raised to the power of given number


ABS(number)

Returns the absolute value of given number


FACT(number)

Returns the factorial of a given number


SEC(number)

Returns the secant of an angle given in radians


LOG10(number)

Returns the logarithm (base 10) of given number


CSC(number)

Returns the cosecant of an angle given in radians


PI()

Return value of Pi


DEGREES(radians)

Convert radians to degrees

RADIANS(degrees)

Convert degrees to radians

INT(number)

Returns the Integer value of given number

FP(number)

Returns a floating-point value of given number

4.2-

DECIMALS(number, maxdecimals)
DECIMALS(number, maxdecimals, forcemaxdecimals)

Returns a floating-point value with the maximum number of decimals. Internally, floating-point values can have many decimal places; this function allows you to reduce the number of decimals, which may be necessary for proper display.
DECIMALS(number, maxdecimals) will return a floating point value with up to the number of decimals defined. I may have fewer decimals if the value is, e.g., an exact integer. 
DECIMALS(number, maxdecimals, forcemaxdecimals) returns a floating-point value with exactly the specified number of decimal places. If the value has fewer decimals, it will be zero-padded.
Examples:

  • DECIMALS(1.234, 2) -> 1.23
  • DECIMALS(1.2, 2) -> 1.2
  • DECIMALS(1.2, 2, true) -> 1.20

4.2-

RND(min, max)

Returns a random value between min and max.

4.2-

Supported Constants

Constant

Description

Version

e

The value of e


PI

The value of PI


TRUE

The boolean true value


FALSE

The boolean false value


NULL

The null value


Supported text functions

Function

Description

Version

LEFT(text, num_chars)

Extracts a given number of characters from the left side of a supplied text string


RIGHT(text, num_chars)

Extracts a given number of characters from the right side of a supplied text string


MID(text, start_num, num_chars)

Extracts a given number of characters from the middle of a supplied text string


REVERSE(text)

Reverse a string


ISNUMBER(text)

Check if a value is a number


LOWER(text)

Converts all letters in the specified string to lowercase


UPPER(text)

Converts all letters in the specified string to uppercase


PROPER(text)

Capitalizes words given text string


TRIM(text)

Removes extra spaces from text


LEN(text)

Returns the length of a text string


REPLACE(old_text, start_num, num_chars, new_text)

Replaces characters specified by location in a given text string with another text string


SUBSTITUTE(text, old_text, new_text)

Replaces a set of characters with another


FIND(find_text, within_text, [start_num])

Returns the location of a substring in a string (case sensitive)


SEARCH(find_text, within_text, [start_num])

Returns the location of a substring in a string (case insensitive)


CONCAT(text1, text2, text3,…)

Combines the text from multiple strings


ISBLANK(text)

Returns TRUE when a given string is null or empty, otherwise return FALSE


REPT(text, repeat_time)

Repeats characters a given number of times


CHAR(char_code)

Return character from ascii code


CODE(char)

Returns a ascii code of a character


VALUE(text)

Convert numbers stored as text to numbers


HEXVALUE(text)

Convert numbers stored as hexadecimal text to numbers. Space characters are ignored, so "01 0A" gives the same result as "010A". Not case-sensitive.

3.12-

HEXSTRING(number, num_chars)

Converts an integer to a hexadecimal string. By default (if num_chars is omitted), it returns a two-character hexadecimal string. If a different length is required, this can be specified with num_chars. The result is zero-padded to achieve the desired length.

4.0-

LPAD(text, count, pad_character)

Adds pad characters to the left until the number of characters is "count".

3.11-

RPAD(text, count, pad_character)

Adds pad characters to the right until the number of characters is "count".

3.11-

HHMMSS(value)

Converts a value in milliseconds to a "hh:mm:ss" string.

3.11-

HHMM(value)

Converts a value in milliseconds to a "hh:mm" string.

3.11-

MMSS(value)

Converts a value in milliseconds to a "mm:ss" string.

3.11-

COUNT(text, text)

Returns the count of how many times a specific string appears in another string, case-insensitive.

Examples:

  • COUNT("ABCXYZabcABCabc","ABC") -> 4

  • COUNT("ABC,DEF,GHI,JKL",",") -> 3

4.2-

STR(something)
STRING(something)

Returns "something" as a string value. "Something" can be any type of value: string, integer, floating-point or boolean.

4.2-

VARTYPE(something)

Returns the value type of the argument. Primarily used to get the type of a variable. 

  • {@l_MyVar:10}{text:#VARTYPE(@l_MyVar)#} => "INT"
  • {@l_MyVar:1.0}{text:#VARTYPE(@l_MyVar)#} => "FP" (requires enabling extended variable mode.)
  • {@l_MyVar:"10"}{text:#VARTYPE(@l_MyVar)#} => "STR"

4.2-

LOADFILE(path)
LOADFILE(path, row)

Returns the content from the referenced file. If a row number is specified, only that row is returned; otherwise, the entire file is returned. The first row in the file is numbered 1.

With a myfile.txt containing the letters A, B, and C on separate rows, the following actions produce the outlined outcomes.

  • {@content:#loadfile("%trevligaspel%/text/myfile.txt"))#} ==> A B and C on three rows
  • {@content:#loadfile("%trevligaspel%/text/myfile.txt",2))#} ==> B

4.2-

FILESAFE(filename)

Returns a string that is safe to be used as a file name. Characters not allowed in a file name are replaced with underscores.

A common use for this function might be to date-stamp a file with the current date and time as the file name. A word of caution: if you use a date format with slashes, like the US date format 14/1/2026, you need to handle the file name separately from the full path.

If you pass a full path to the function (C:/Users/userid/Documents/Trevliga Spel/14/01/2026 8:53:01 pm.txt), it can't distinguish the boundary between the directory path and the file name because slashes are used in both parts. You need to first store the date in a variable, make the variable file-safe, and then concatenate it with the full path. 

  • {@file:#filesafe(datetime("datetime") + ".txt")#}
  • {@fullpath:#filesafe("%trevligaspel%/" + @file)#}

 

4.2-

Supported list functions

List functions handle comma-separated lists and include methods to get, set, add, or remove list items, as well as count the items. The first item in a list has index 1. Item texts must be enclosed in quotation marks to prevent the Math library from treating them as variables.

Please note that methods that change a list in a variable do not automatically update the variable's value; you need to assign the method's result to the variable.
{@l_MyVar:#additem(@l_MyVar,"all")#}

Function

Description

Version

GETITEM(index, list)
PART(index, list)

Returns the item at the specified index in the list. If the index is out of bounds, an empty item is returned.
getitem(3,"These,are,the,parts") => "the"

4.2-

SETITEM(index, list, newItem)

Returns a new list with the new item at the specified index, replacing any item previously at that position. If the index exceeds the current number of items in the list, the list will be expanded with empty items to reach the necessary item count.
setitem(3,"These,are,the,parts","all") => "These,are,all,parts"


4.2-

ADDITEM(list, newItem)

Returns a new list with the new item appended to the end.
additem("These,are,the,parts","all") => "These,are,the,parts,all"

4.2-

INSERTITEM(index, list, newItem)

Returns a new list with the new item inserted at the specified index. If the index exceeds the current number of items in the list, the list will be expanded with empty items to reach the necessary item count.
insertitem(3,"These,are,the,parts","all") => "These,are,all,the,parts"

4.2-

REMOVEITEM(index, list)

Returns a new list with the item at the specified index removed.
removeitem(3,"These,are,the,parts") => "These,are,parts"

4.2-

REPLACEITEM(list, oldItem, newItem)

Returns a new list with the old item replaced by the new item. The function is case sensitive. If the item is not found, the list is returned unchanged.
replaceitem("These,are,the,parts", "are", "all") => "These,all,the,parts"

4.2-

ITEMCOUNT(list)

Returns the number of items in a list.
itemcount("These,are,the,parts") => 4

4.2-

ITEMINDEX(list, item)

Returns the index of the specified item. The function is case sensitive. If the item is not found, 0 is returned.
itemindex("These,are,the,parts", "These") => 1

4.2-

Supported date and time functions

Date and time functions return information formatted according to the language settings of the computer. For functions returning strings, examples are provided for the results in US English and Swedish.

The DATETIME function can be used with an index for a format, a format name, or a custom format based on the C# DateTime Standard or Custom format specifiers.

Function

Description

Version

DATETIME()
DATETIME(1)
DATETIME("datetime")

Returns the full date and time:
"1/11/2026 2:00:27 PM", "2026-01-11 13:55"

4.2-

DATETIME(2)
DATETIME("date_short")

Returns a short date:"
1/11/2026", "2026-01-11"


4.2-

DATETIME(3)
DATETIME("date_long")

Returns a long date:
"Sunday, January 11, 2026", "den 10 januari 2026"

4.2-

DATETIME(4)
DATETIME("time_short")

Returns time without seconds:
"2:00 PM", "13:54"

4.2-

DATETIME(5)
DATETIME("time_long")

Returns time with seconds:
"2:00:24 PM", "13:54:57"

4.2-

DATETIME(6)
DATETIME("year")

Returns the year:
2026

4.2-

DATETIME(7)
DATETIME("month")

Returns the ordinal number of the month.:
1

4.2-

DATETIME(8)
DATETIME("month_short")

Returns the abbreviated name of the month:
"Jan.", "jan."

4.2-

DATETIME(9)
DATETIME("month_long")

Returns the name of the month:
"January", "januari"


4.2-

DATETIME(10)
DATETIME("day")

Returns the current day's number in the month:
10


4.2-

DATETIME(11)
DATETIME("dayofweek")

Returns the current day's number in the week:
5


4.2-

DATETIME(12)
DATETIME("dayofweek_short")

Returns the short name of the weekday:
"Sun", "sön"


4.2-

DATETIME(13)
DATETIME("dayofweek_long")

Returns the name of the weekday:
"Sunday", "söndag"


4.2-

DATETIME(14)
DATETIME("dayofyear")

Returns the current day's number in the year:
100


4.2-

DATETIME(15)
DATETIME("hour")

Returns the hour in 12-hour or 24-hour format without the AM/PM indicator.
10


4.2-

DATETIME(16)
DATETIME("minute")

Returns the minutes:
34


4.2-

DATETIME(17)
DATETIME("second")

Returns the seconds:
23


4.2-

DATETIME(_custom_)

A custom format based on the C# DateTime Standard or Custom format specifiers. Example:
DATETIME("Y") => "April, 2008"


4.2-

Supported bitwise functions

Function

Description

Version

BITAND(number, number)

Returns an integer that is the result of a bitwise AND operation.


BITOR(number, number)

Returns an integer that is the result of a bitwise OR operation.


BITXOR(number, number)

Returns an integer that is the result of a bitwise XOR operation


BITNOT(number)

Returns an integer that is the result of a bitwise NOT operation


BITLSHIFT(number, steps)

Returns an integer that is the result of a bitwise left shift the number of steps defined


BITRSHIFT(number, steps)

Returns an integer that is the result of a bitwise right shift the number of steps defined


BITGET(number, position)

Returns an integer that is either 0 or 1 depending on the bit at the specified position. The least significant bit is at position 0.


4.2-

BITSET(number, position, bitvalue)

Returns an integer that is the number with the bit at the specified position set to the specified bit value. The least significant bit is at position 0.


4.2-