Game Development Reference
In-Depth Information
In this spreadsheet the first column is used as a text identifier field. This is just
a string of text that we can use in our source code and datafiles to represent a
particular string of text.
The first row is used to indicate which language each column of the spreadsheet
represents. In the example, we have used the standard two letter ISO country codes
to represent the supported languages, namely English (EN) and French (FR).
The rest of the spreadsheet is then just the actual text that we want to appear in
the game.
Getting the text into the game
With the text for our game now in a spreadsheet, how do we access it from inside
our game code? The answer is to process the spreadsheet into a format that is easy
for us to load and use in game code.
Comma-separated values files
One option would be to export the text as a Comma-Separated Values ( CSV ) file
from our spreadsheet program. This is a simple text-only format that outputs each
row of the database as a separate line in the file, with the contents of each cell listed
separated by commas.
The trouble with this approach is it can be error-prone. Having a comma in the text
of one of your strings can play havoc with the output since the comma is already
used to indicate the end of one string and the beginning of the next. This is often
gotten around by enclosing each string in quote marks, but then this can cause
further problems if a string needs to include a quote mark too!
Remember also that IwGxFont expects text to be supplied in UTF-8 format by
default. If you are supporting languages such as Japanese or Korean, this becomes
very important and some spreadsheet programs do not support exporting a CSV File
in UTF-8 format.
Processing using a Python script
A much better method of getting the text out of a spreadsheet and into our game is
to process the spreadsheet into a simple datafile, which can be easily loaded into our
game. To demonstrate this, we'll be making use of the Python scripting language.
Python may have a rather strange approach to code layout (the scoping level of your
code is indicated by how much it is indented, rather than using notation such as
curly braces to indicate the start and end of a section of code), but there is no denying
that it is extremely good at this kind of task.
 
Search WWH ::




Custom Search