User Defined Functions

ADRIFT 5 Help ›› Creating Games ›› Functions ››
Parent Previous Next

User Defined Functions

User Defined Functions allow you to create your own custom functions, with parameters if necessary, that you can use within any text sections.  


ADRIFT Developer must not be in Simple Mode for the User Defined Functions button to be visible on the main toolbar.


User Defined Functions can be used to simplify complex expressions that you may want to use repeatedly throughout your game.


Creating a new User Defined Function brings up the editor, like so:



Name is the name of your function.  This is how you will reference it in your game.  For example, if you give it the name MyFunction, then you would use the function in the game by typing %MyFunction% in a text area.  If your function has parameters, these should be passed into the function within square brackets, and comma separated.


You can give your function any number of parameters.  Parameters can be Objects, Characters, Locations, Numbers or Text.  Each parameter must be given it's own name, and can thereafter be referenced in the function output by typing the parameter name within percent symbols.


The Output can be any text you want, but it can reference any parameters passed in.  Additionally, any alternative descriptions you add can define restrictions based upon the parameters.

Examples

Items Held (Player)

Say you wanted to create a simple function to return the number of items held by the player.  This would normally require you to write an item function that some may find unwieldy.  So you could do the following:


       Name:                HeldCount

       Parameters:        Not Required

       Output:                %Player%.Held.Count

You can then use this function like so:


Syntax

%HeldCount%

Parameters

none


Items Held (Any Character)

Similarly, you could create the same function as above, but have this work for any specified character.  This time, we need to add a parameter to the function.


       Name:                HeldCount

       Parameters:        Name: who        Type: Character

       Output:                %who%.Held.Count

You can then use this function like so:


Syntax

%HeldCount[who]%

Parameters

who

The key of the character you want to return the number of held items for