Class Asset

From TrainzOnline
Jump to: navigation, search


The term Asset refers to an individual item of content for Trainz. All assets have a KUID which provides unique identification, a config.txt file which provides configuration data and an optional StringTable which is a repository for indexed string values and a means of providing for foreign language translation.

An asset provides the information that TRS needs to place a new object, also referred to as an instance of the asset, into the game environment.

Some of the methods in this class refer to the asset's kuid-table, a container within config.txt which lists the kuids of other assets which are required for proper functioning. These assets are often listed using an integer index:

kuid-table {
   0    <kuid:44179:60013>
   1    <kuid:-3:10110>
}

The kuid-table is however in Soup format which allows descriptive labels to be used instead. This makes it easier for a script to refer to the KUID or the asset concerned:

kuid-table {
   coal           <kuid:44179:60013>
   greencorona    <kuid:-3:10110>
}

Contents

FindAsset

public native Asset FindAsset(string kuidTableAssetName)
Parameters
  • kuidTableAssetName = Tag value referencing a dependency as entered in the kuid-table from the asset's config.txt.
Returned Value
  • A reference to the asset represented by the kuid-table entry.
Syntax
// kuid-table of this asset
kuid-table {
   green  <kuid:-3:10110>
}
Asset asset = GetAsset().FindAsset("green");  // returns a reference to the built-in green corona
Notes
See Also


GetConfigSoup

public native Soup GetConfigSoup(void)
Parameters
  • None
Returned Value
  • The contents of the config.txt file belonging to the scripted asset in Soup format.
Syntax
Soup soup = GetAsset().GetConfigSoup();
Notes
  • The Soup returned by this method will be read only.
  • Sub containers within config.txt can be accessed as sub soups:
Soup meshTable = GetAsset().GetConfigSoup().GetNamedSoup("mesh-table");


GetKUID

public native KUID GetKUID(void)
Parameters
  • None
Returned Value
  • KUID of current asset
Syntax
KUID kuid = GetAsset().GetKUID();
Notes
  • Return format is <kuid:1234:5678> or <kuid2:1234:5678:9> as appropriate.


GetLocalisedName

public native string GetLocalisedName(void)
Parameters
  • None
Returned Value
  • String representing the localised username of the asset.
  • For English versions of the game this will be the contents of the config.txt tag username
Syntax
string username = GetAsset().GetLocalisedName();
Notes
  • For other language versions the result will be the equivalent localised username, if it exists.
  • For German, username-de
  • For Italian, username-it
  • If there is no localised tag, then the contents of username will be returned.


GetStringTable

public native StringTable GetStringTable(void)
Parameters
  • None
Returned Value
Syntax
StringTable strings = GetAsset().GetStringTable();
Notes
  • Any asset can have a StringTable in its configuration that consists of a collection of named string elements in Soup format.
  • Foreign language versions will return a localised StringTable, using the config.txt container string-table-es for instance. This provides for translation of the user interface of an asset.
  • The returned StringTable object provides methods to easily access these strings.


LookupKUIDTable

public native KUID LookupKUIDTable(string kuidTableAssetName)
Parameters
  • kuidTableAssetName = Name referencing a dependency KUID as entered in the kuid-table from the asset's config.txt.
Returned Value
  • A reference to the KUID represented by the kuid-table entry.
Syntax
// kuid-table of this asset
kuid-table {
   green  <kuid:-3:10110>
}
KUID kuid = GetAsset().LookupKUIDTable("green");  // returns a reference to the built-in green corona
Notes
  • Returns null if the kuid-table entry is invalid or if it does not exist.
See Also


Code Examples

Related Methods

World.FindAsset()

TrainzGameObject.GetAsset()

World.GetAssetList()

Categories

Personal tools