Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The script constants have been expanded with a large number of new constants.
The constants have also been grouped in collapsible groups rather than a single large list.
The search filter is also available to search by text

List Script Constants

Datatypes

There are a number of new datatypes available. Some related to the new features, others are useful for general scripting.

New Datatypes

  • DATATYPE_AGENT - This is an agent object for use with diplomacy
  • DATATYPE_AGENTCOMMAND - This is a diplomacy task use by agents in diplomacy, similar to ship/station commands
  • DATATYPE_TABLE - See below for Table Info
  • DATATYPE_LOADOUTRET - This is a return value from the ship loadout script commands
  • DATATYPE_MERCHANT - This is for the merchant objects (Barter Menu) for use with script commands to control the barter system
  • DATATYPE_DEALER - Similar to Merchant, but used on the Black Market instead of Barter, most commands can use either merchant or dealer
  • DATATYPE_CARRIERROLE - This is the ship role for use with the carrier management, i.e. Fighter, Defender, Drone, etc
  • DATATYPE_COMMANDMENU - This is one of the sub menus in the ship command menu, i.e. Trade, Combat, General, etc. For use with script commands dealing with command menu changes
  • DATATYPE_GSUBTYPE - This is the Global Subtype class of objects, used by some ship/station information commands
  • DATATYPE_MAINTYPE - This is the main type of a variable in the script engine
  • DATATYPE_TIME - This is a time variable for using ms timing, there are various commands allowing you to manipulate time values
  • DATATYPE_XMLDATA - This stores a parsed xml data structure, for use with reading and writing xml files

 

Tables

Tables will store data based on keys, previously, you had some limited table support by using the global/local variables to store data in string keys, which used tables internally to store this. Now you have more access to the table system, and can use them locally within your scripts. Like arrays, tables are stored by reference, so passing tables between scripts, or storing them in local/global variables will store the pointer to the table, so the same table can be modified across multiple scripts.

The key can be any data type, and you can mix data types within the same table. There are a few exceptions, any datatype where the sub value could be 0 will not function correctly in a table, for example the relation/neutral, most datatype will work fine however.

The main advantage with tables, is that you don't need to set the size of the table, or resize it, it will grow/shrink as needed and is generally quicker at this than arrays. Checking if a key is in the table is also quicker than checking in an array.
However, you cant control the order things will be in a table, so if your data needs to be in a set order, i.e. a sorted list of ships, then it will need to be in an array instead.

To use tables, you first need to allocate one

Code Block
themeMidnight
$table = table alloc

then you add/set data using the normal array commands

Code Block
themeMidnight
$table["key"] = value
$value = $table["key"]

To iterate through a table list you use the get table next command
The key value is the previous key, use null to get the first key in the list.

Code Block
themeMidnight
$key = get next key: table=$table, key=[NULL]
while $key
...
$key = get next key: table=$table, key=$key
end

NOTE: if you need to remove an item from the table while iterating through, make sure you get the next key before removing, IE:

Code Block
themeMidnight
$key = get next key: table=$table, key=null
while $key
$next.key = get next key: table=$table, key=$key
remove $key from table $table
$key = $next.key
end

You can also get all the keys as an array, and iterate through that array instead, this can also allow you to sort the table

NOTE: some of the new script commands will use tables as arguments or return values