Class Asset

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
m (Change link to library reference, not language reference)
m (Add links between language reference pages)
 
Line 34: Line 34:
 
;Notes
 
;Notes
 
*Returns null if the kuid-table entry is invalid or if it does not exist.
 
*Returns null if the kuid-table entry is invalid or if it does not exist.
*This method is the equivalent of ''World.FindAsset(GetAsset().LookupKUIDTable(kuidTableName))''
+
*This method is the equivalent of ''[[Class World#FindAsset|World.FindAsset]]([[Class TrainzGameObject#GetAsset|GetAsset()]].[[#LookupKUIDTable|LookupKUIDTable]](kuidTableName))''
 
;See Also
 
;See Also
 
*[[#LookupKUIDTable|LookupKUIDTable()]]
 
*[[#LookupKUIDTable|LookupKUIDTable()]]
Line 40: Line 40:
  
 
==GetConfigSoup==
 
==GetConfigSoup==
{{MethodHeader|public native Soup GetConfigSoup(void)}}
+
{{MethodHeader|public native [[Class Soup|Soup]] GetConfigSoup(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 46: Line 46:
 
*The contents of the ''config.txt'' file belonging to the scripted asset in [[Soup]] format.
 
*The contents of the ''config.txt'' file belonging to the scripted asset in [[Soup]] format.
 
;Syntax
 
;Syntax
  Soup soup = GetAsset().GetConfigSoup();
+
  Soup soup = [[Class TrainzGameObject#GetAsset|GetAsset()]].GetConfigSoup();
 
;Notes
 
;Notes
 
*The Soup returned by this method will be read only.
 
*The Soup returned by this method will be read only.
 
*Sub containers within ''config.txt'' can be accessed as sub soups:
 
*Sub containers within ''config.txt'' can be accessed as sub soups:
  Soup meshTable = GetAsset().GetConfigSoup().GetNamedSoup("mesh-table");
+
  Soup meshTable = [[Class TrainzGameObject#GetAsset|GetAsset()]].GetConfigSoup().[[Class Soup#GetNamedSoup|GetNamedSoup]]("mesh-table");
 
<br>
 
<br>
  
 
==GetKUID==
 
==GetKUID==
{{MethodHeader|public native KUID GetKUID(void)}}
+
{{MethodHeader|public native [[Class KUID|KUID]] GetKUID(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 73: Line 73:
 
*For English versions of the game this will be the contents of the ''config.txt'' tag ''username''
 
*For English versions of the game this will be the contents of the ''config.txt'' tag ''username''
 
;Syntax
 
;Syntax
  string username = GetAsset().GetLocalisedName();
+
  string username = [[Class TrainzGameObject#GetAsset|GetAsset()]].GetLocalisedName();
 
;Notes
 
;Notes
 
*For other language versions the result will be the equivalent localised username, if it exists.
 
*For other language versions the result will be the equivalent localised username, if it exists.
Line 82: Line 82:
  
 
==GetStringTable==
 
==GetStringTable==
{{MethodHeader|public native StringTable GetStringTable(void)}}
+
{{MethodHeader|public native [[Class StringTable|StringTable]] GetStringTable(void)}}
 
;Parameters
 
;Parameters
 
*None
 
*None
Line 96: Line 96:
  
 
==LookupKUIDTable==
 
==LookupKUIDTable==
{{MethodHeader|public native KUID LookupKUIDTable(string kuidTableAssetName)}}
+
{{MethodHeader|public native [[Class KUID|KUID]] LookupKUIDTable(string kuidTableAssetName)}}
 
;Parameters
 
;Parameters
 
*'''kuidTableAssetName''' = Name referencing a dependency KUID as entered in the ''kuid-table'' from the asset's ''config.txt''.
 
*'''kuidTableAssetName''' = Name referencing a dependency KUID as entered in the ''kuid-table'' from the asset's ''config.txt''.
Line 107: Line 107:
 
  }</font>
 
  }</font>
  
  KUID kuid = GetAsset().LookupKUIDTable("green");  // returns a reference to the built-in green corona
+
  KUID kuid = [[Class TrainzGameObject#GetAsset|GetAsset()]].LookupKUIDTable("green");  // returns a reference to the built-in green corona
 
;Notes
 
;Notes
 
*Returns null if the kuid-table entry is invalid or if it does not exist.
 
*Returns null if the kuid-table entry is invalid or if it does not exist.
Line 118: Line 118:
 
==Related Methods==
 
==Related Methods==
  
World.FindAsset()
+
[[Class World#Find Asset|World.FindAsset()]]
  
 
[[Class TrainzGameObject#GetAsset|TrainzGameObject.GetAsset()]]
 
[[Class TrainzGameObject#GetAsset|TrainzGameObject.GetAsset()]]
  
World.GetAssetList()
+
[[Class World#GetAssetList|World.GetAssetList()]]
  
 
==Categories==
 
==Categories==
 
[[Category:Script Class]]
 
[[Category:Script Class]]

Latest revision as of 21:32, 29 December 2020


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

[edit] 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


[edit] 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");


[edit] 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.


[edit] 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.


[edit] 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.


[edit] 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


[edit] Code Examples

[edit] Related Methods

World.FindAsset()

TrainzGameObject.GetAsset()

World.GetAssetList()

[edit] Categories

Personal tools