Using Message Arguments


This tutorial follows on from creating of Text files and teaches you how to use arguments to format your messages to include varibles via scripts, the previous guide can be found here.

There are 2 main commands to use, there are the "sprintf" commands, that allow you to format your messages using varibles. They are found in the General Commands menu.


The first, the sprintf: fmt =, command is for formating a string to how you like, and the 2nd, the sprintf: pageid=, command is simlar, but instead of taking a string to format, it gets the text directly from a text file.


Formating Strings

Using the first command, the sprintf: fmt =, you can format a string using varibles from the script. The first argument, <Var/String>, is the string to format, this can be any string you like, and the formated string is then returned to the <RetVar>.

Heres a simple example, although fairly pointless to use.


This simply trys to format the string, "This is a String". As there are no special characters, there is nothing to format, so the $text varible will now contain the string "This is a String".

Now, we should ass some special characters, the main one to use is the "%s", which will be replaced with one of the arguments. As you can see, there are 5 extra arguments after the string, each one is a varible to replace a %s in the string. The first %s is replaced by the first argument, and so on.


This next example includes a %s in the string. So this will be replaced with what ever is in the $string varible. So $text will now equal, "String: This is a String". The same can be used for objects, such as the player's ship.


This will put your current ships name into the string, ie, $text could be, "Your Ship: Your Split Mamba".

For more than one varible, you simply add more %s into the string, upto a maximum of 5 in any one command.

2 Arguments

Here we have 2 varibles used, and will display your ships name, and your current name, ie the pilots name.


Strings from Text Files

Now you can use formatting in strings, you can add the string to a text file instead. For the example above, you can add the string, "Ship: %s, Pilot: %s" into your text file in a page id of your choise.

<?xml version="1.0" encoding="UTF-8" ?>
<language id="44">
<page id="1000">
 <t id="1">Ship %s, Pilot: %s</t>

This would be the contents of your text file, then to use that in a script, you use the other sprintf command, the sprintf: page id= command. The first argument is the page id to use, in this example, it would be 1000, and the second argument is the id in that page, the t id, which would be 1.

The rest of the 5 arguments are the same as the previous command, and are used to replace the %s in the string.

Page ID

This will return the same string as before, but the string will be read from a text file instead. The advantage of this, is that you can then format your scripts for different languages, or make changes to the text without having to edit the scripts themselves.

<< Prev (Creating AL Plugin)
Next (Incomming Questions) >>