Zonkmachine - Mission Flavours OLD

From PioneerWiki
Jump to: navigation, search

Mission flavours

A script can define a mission, and then place many instances of it onto many bulletin boards. A script that introduces many instances should provide some variety; it would harm immersion if all delivery missions were worded identically, for example.

To introduce variety, we can use tables, which contain all of the lines needed for bulletin board forms, messages and so forth. It's then a simple matter to use a similar, but differently worded, table to make the same misison appear different. A flavour might look like this:

{
    title = "Shill bidder wanted for auction",
    greeting = "Hi there. Want to earn some quick cash?",
    yesplease = "Sure. What do you need me to do?",
    nothanks = "No, ta - this looks a bit shady.",
}

An alternative flavour might look like this:

{
     title = "Help me win an auction.",
     greeting = "Hello. I'll pay you to place fake bids for me. Interested?",
     yesplease = "Yes, I like to live dangerously.",
     nothanks = "No thanks; I'd rather not get arrested for fraud.",
}

Ideally, we just need a table with as many of these as we can be bothered to write, then select one at random.

There are issues with translation, though. Because flavours are often full of colloquial language, and can feature several ways of saying basically the same thing, translating them all word-for-word is not necessarily productive. To this end, the Translate system features a pair of methods which can ease the handling of flavours, especially in different languages.

The Translate:AddFlavour() method allows a flavour to be added, and marked as being of a specific language. By convention, these statements would appear in the script's Languages.lua file so that translators could see them and be inspired to write some in other languages. The method takes three arguments. The first is the language of the flavour, as a string. The second is a name, so that the Translate class can give flavours back to the correct script. The third is the flavour table itself. If my script was named TestModule, I might define the two flavours above in my Languages.lua as follows:

Translate:AddFlavour('English','TestModule',{
     title = "Shill bidder wanted for auction",
     greeting = "Hi there. Want to earn some quick cash?",
     yesplease = "Sure. What do you need me to do?",
     nothanks = "No, ta - this looks a bit shady.",
})

Translate:AddFlavour('English','TestModule',{
     title = "Help me win an auction.",
     greeting = "Hello. I'll pay you to place fake bids for me. Interested?",
     yesplease = "Yes, I like to live dangerously.",
     nothanks = "No thanks; I'd rather not get arrested for fraud.",
})

As an added benefit, Translate:AddFlavour() checks all flavour tables for uniformity. It does this by comparing all of the table's keys with that of the first English flavour that was specified; a technical consequence of this is that an English flavour needs to come first in your Languages.lua file, otherwise Pioneer will give you an error.

To fetch the flavours into your script, use Translate.GetFlavours(). It takes a single argument, which is the module name that was specified in AddFlavour()'s second parameter. It doesn't matter to Translate how many flavours there are in each language, or whether it's an equal number. If my current language is not English, and there are no flavours in that language, English flavours will be used instead. If there is only one flavour in my language, I will only see that one variety.

The following example will select a random flavour from my flavour tables.

local all_flavours = Translate:GetFlavours('TestModule')
local flavour = all_flavours[Engine.rand:Integer(1,#all_flavours)]

GetFlavours() returns a table of flavours. The second line of code generates a random number between 1 and the number of flavours in that table, and returns that flavour from the table. After this, flavour.title will either be "Shill bidder wanted for auction" or "Help me win an auction.". Adding more flavours means more variety.