User functions

From ADRIFT 5 Manual Wiki
Jump to: navigation, search
Text Overrides
User functions

These are functions which you create yourself. You can specify any number of parameters to be used in the function call, and these can be any combination of object references, character references, location references, numbers or text. A text box is used to provide the text that is output by the function, and this can contain other functions and embedded expressions to calculate and format the desired output. If the output of the function needs to change depending on restrictions then you can create Alternate Descriptions for full control over the output text.

Creating a User Function

A user function can be created by right-clicking on a folder and choosing "Add New" and "User Function",

or by pressing the IconUserFunc.jpg"User Function" button on the main toolbar ribbon (When not in simple mode).


In this example we have created a user function called "AllHeld", which has no parameters and will output the result of the "%Player%.Held(True).Count" item function.

This function can then be used as a shorter way of printing out the number of objects that the player is currently carrying.

Using a user function in text or an expression

The new function we created above can now be used in a text box or expression by placing a "%" (percent) symbol before and after its name, just like you would with General Functions or variables.

You are currently carrying %AllHeld% objects.

When the above line is printed ADRIFT will execute your user function which contains the Player%.Held(True).Count item function.

If the player is carrying twelve objects then it will print:

You are currently carrying 12 objects.

In an expression you can use the result of a user function the same way as any other function. If it returns a number then you can compare it to another number or use it in a calculation, eg:

if( %AllHeld% = 0, "You are not carrying anything.", 
"You are carrying " & %NumberAsText[ %AllHeld% ]% & " objects." )

Adding Parameters

To add a parameter to the function you need to give it a name and then specify if it is a number, text, or a character, object or Location reference.


In the text box of the user function you can the use the name of the parameter in an expression or as the parameter of another function. In this example we use an IF expression function to check if the "Money" parameter is less than 100. If it is then we simply print it as that many cents, otherwise we use various expression functions to format it into a fixed-point value that displays it as dollars and cents. The value 1204 is displayed as "$ 12.04"

This function can now be used anywhere that we want to display an amount as a monetary value. The parameter value to use is given inside of the square brackets.

If a variable called %PlayersMoney% contains the amount of money that the player has, in cents, then we can print it as a dollars and cents amount like this:

You currently have %Cash[%PlayersMoney%]% in your wallet.

If %PlayersMoney% contains the value 1204 then this will print:

You currently have $ 12.04 in your wallet.

If you add more parameters to the function then use comma's to separate them when you call the function:

%MyFunc[ 42, 18, %object%, Character10 ]%

<<< SynonymMain PageSimple mode >>>