Making a simple BBS message tutorial (Page 3 of 3)

Written by Roguey,

Making a simple BBS message tutorial, written by Roguey


Loading from the language file

Lets upgrade our little script to load text directly from a language file (like how it should). There are 2 reasons why it is better to load our text from a language, they are:
  • The text can be translated into other languages, and is loaded in depending on the users language,
  • The ability to edit the text in your own text editor,

So at first we need to create a new language file. Language files are in xml format and can be compressed or uncompressed. If a xml is compressed it will have an .pck extension. We can write our own xml with a simple txt editor (like notepad).

In this guide I am going to use the english language (ie. 44) but if your game is German or French etc. then you will need to change the 44 number to another, ie:
  • 07 for Russian,
  • 33 for French,
  • 34 for Spanish,
  • 39 for Italian,
  • 42 for Czech,
  • 44 for English,
  • 48 for Polish,
  • 49 for German,

So create a new text file inside your X3\t folder, named 440009.xml - swap the 44 if required. Now copy and paste the code below into your xml file:

<?xml version="1.0" encoding="utf-8" ?>
<language id="44">

<page id="999880" title="News reports" descr="0">
<t id="1">[author]Roguey[/author][title]Important news[/title]\nHello the x galaxy! im a new scripter posting here using the language files! Please be nice</t>
</page>
</language>

Remember to change language id="44" to match your language number. Save the file. Please note the game wont see this file until you exit game (back to desktop) and load/start a new game.

Now that's done, we need to update our script to load from a language file. So back to our script (plugin.bbs.example1) and delete the line (by using delete) that says:

$msg = 'Hello the x galaxy! im a new scripter posting here. Please be nice

For me this line was on line 10, however it may differ depending on your layout and if you added any comments. This time we want to load the string from the xml file. To do this insert a new line (before set quest status) and press enter. Now we want sprintf which is located on the General Command page, which looks like this:

<RetVar> = sprintf: page id=<Var/Number> textid=<Var/Number>, <Value>, <Value>, <Value>, <Value>, <Value>

When ask for script input, set the variable msg. Now we need to set two pieces of information: page id and textid. The page id can be found in the xml (page id="999880") and the textid (t id="1"). So enter in 999880 for the page id and set the textid to 1. So you should have this:

Our finished simple bbs script

Just one more thing to do, load in the language file. Without loading in the language file we will get a readtext error. The xml file only needs loading once per game and not every time this script is ran. So.. the best place to stick the load is in our old setup.bbs.basic script. So save this script and open up our setup script.

Now insert a new blank line at line 1. Press enter, General Commands now find this command:

load text: id=<Var/Number>

When ask for a value, enter 9. So why 9? 9 refers to the xml number, remmeber it was 440009.xml? Thats why! All done! So save the script and restart your game. With a little looking around you should see this:

Our improved bbs script

That looks much better eh? well thats it.. our own BBS news posts.

Next: End of guide
<< Previous Page