Difference between revisions of "Oolite JavaScript Reference: Manifest"
Line 94: | Line 94: | ||
'''list''' : Array (read-only) | '''list''' : Array (read-only) | ||
Array of objects. Each object contains the info for a commodity present in the player's hold: | Array of objects. Each object contains the info for a commodity present in the player's hold: | ||
− | commodity : String | + | commodity : String (corresponds to manifest["commodity"]) |
quantity : Integer | quantity : Integer | ||
− | + | displayName : String (commodity display name, can be different for different languages) | |
unit : String ('t' = tons, 'kg' = kilograms, 'g' = grams) | unit : String ('t' = tons, 'kg' = kilograms, 'g' = grams) | ||
+ | |||
+ | Example usages of the manifest.list property | ||
+ | |||
+ | var i, m; | ||
+ | |||
+ | // for certain types of cargo (like gem-stones) player.ship.cargoSpaceUsed can still be 0 | ||
+ | // even if we're carrying 100 or more. | ||
+ | log('The player is currently carrying ' + (manifest.list.length > 0 ?'the following:' : 'nothing.')) | ||
+ | |||
+ | for (i = 0; i<manifest.list.length;i++) | ||
+ | { | ||
+ | m = manifest.list[i]; | ||
+ | log( m.quantity + m.unit + ' of '+ m.displayName ); | ||
+ | } | ||
+ | and | ||
+ | var i, c; | ||
+ | |||
+ | // now remove at least ''1 of / 20% of'' each type of cargo carried. | ||
+ | for (i = 0; i<manifest.list.length;i++) | ||
+ | { | ||
+ | c = manifest.list[i].commodity; | ||
+ | manifest[c] = Math.floor(manifest[c] * .8); | ||
+ | } | ||
[[Category:Oolite scripting]] | [[Category:Oolite scripting]] |
Revision as of 23:33, 10 December 2009
Prototype: Object
This class was added in Oolite test release 1.74.
Manifest
provides direct access to the cargo carried by the player.
Contents
Properties
food
food : Integer (read/write)
Quantity of food in the players ship.
Awarding the player with extra 10 tons of food can be done in different ways:
Manifest.food += 10; or player.ship.manifest.food += 10; or Manifest["food"] += 10;
If there were less than 10 tons of cargo space available, any extra cargo is silently discarded.
textiles
textiles : Integer (read/write)
Quantity of textiles in the players ship.
radioactives
radioactives : Integer (read/write)
Quantity of radioactives in the players ship.
slaves
slaves : Integer (read/write)
Quantity of slaves in the players ship.
"liquor/wines"
liquor/wines (or liquorWines): Integer (read/write)
Quantity of liquor/wines in the players ship.
Access the liquor/wines quantity on the hold via either
Manifest["liquor/wines"] or Manifest.liquorWines
luxuries
luxuries : Integer (read/write)
Quantity of luxuries in the players ship.
narcotics
narcotics : Integer (read/write)
Quantity of narcotics in the players ship.
computers
computers : Integer (read/write)
Quantity of computers in the players ship.
alloys
alloys : Integer (read/write)
Quantity of alloys in the players ship.
firearms
firearms : Integer (read/write)
Quantity of firearms in the players ship.
furs
furs : Integer (read/write)
Quantity of furs in the players ship.
minerals
minerals : Integer (read/write)
Quantity of minerals in the players ship.
gold
gold : Integer (read/write)
Quantity of gold in the players ship.
platinum
platinum : Integer (read/write)
Quantity of platinum in the players ship.
"gem-stones"
gem-stones (or gemStones): Integer (read/write)
Quantity of gem-stones in the players ship.
Access to the gem-stones property is via
Manifest["gem-stones"] or Manifest.gemStones
"alien items"
alien items (alternative name alienItems): Integer (read/write)
Quantity of alien items in the players ship.
Access the alien items property either via
Manifest["alien items"] or Manifest.alienItems
list
list : Array (read-only)
Array of objects. Each object contains the info for a commodity present in the player's hold:
commodity : String (corresponds to manifest["commodity"]) quantity : Integer displayName : String (commodity display name, can be different for different languages) unit : String ('t' = tons, 'kg' = kilograms, 'g' = grams)
Example usages of the manifest.list property
var i, m; // for certain types of cargo (like gem-stones) player.ship.cargoSpaceUsed can still be 0 // even if we're carrying 100 or more. log('The player is currently carrying ' + (manifest.list.length > 0 ?'the following:' : 'nothing.')) for (i = 0; i<manifest.list.length;i++) { m = manifest.list[i]; log( m.quantity + m.unit + ' of '+ m.displayName ); }
and
var i, c; // now remove at least 1 of / 20% of each type of cargo carried. for (i = 0; i<manifest.list.length;i++) { c = manifest.list[i].commodity; manifest[c] = Math.floor(manifest[c] * .8); }