Types/Order: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
m (typo)
(more simple explanation, more examples)
Line 1: Line 1:
The order property is a simple [[Types/string|string]]. When the game compares 2 like prototypes if the order strings aren't equal they're [[:Wikipedia:Lexicographical_order|lexicographically compared]] to determine if a given prototype comes before or after another. When the order strings are equal the game then falls back to comparing the prototype names to determine order.
== Basic ==
The order property is a '''simple''' [[Types/string|string]]. When the game needs to sort prototypes, it looks at their order properties and sorts those alphabetically. So, something with the order "a" comes before something with the order "b" or "c". The "-" or "[]" structures that can be found in vanilla order strings ''do not'' have any special meaning.


Example: The second item is shown before the first one (in the crafting grid/inventory etc)
== Advanced ==
When the game compares 2 like prototypes if the order strings aren't equal they're [[:Wikipedia:Lexicographical_order|lexicographically compared]] to determine if a given prototype comes before or after another. When the order strings are equal the game then falls back to comparing the prototype names to determine order.


  {
== Examples ==
 
=== Two item prototypes ===
The second item is shown before the first one (in the crafting grid/inventory etc)
 
<syntaxhighlight lang="lua">{
     type = "item",
     type = "item",
     name = "item-1",
     name = "item-1",
     order = "a-d",
     order = "ad",
   },
   },


Line 12: Line 19:
     type = "item",
     type = "item",
     name = "item-2",
     name = "item-2",
     order = "a-b",
     order = "ab",
  },
  },</syntaxhighlight>
 
=== Some sorted strings ===
Using a UTF-8 character list, the sort order of special characters can identified, here the sort order for common characters:
* "-"
* "0"
* "9"
* "A"
* "Z"
* "["
* "]"
* "a"
* "z"
 
Example using the above ordering:
* "a"
* "ab"
* "azaaa" (<code>b</code> is sorted before <code>z</code>, so "ab" comes before "az", regardless of the rest of the letters after "az")
* "b"
* "b-zzzz"
* "b[aaaa]" (<code>[</code> is sorted after <code>-</code> in UTF-8)
* "bb" (<code>b</code> is sorted after <code>[</code> in UTF-8)

Revision as of 10:41, 6 September 2018

Basic

The order property is a simple string. When the game needs to sort prototypes, it looks at their order properties and sorts those alphabetically. So, something with the order "a" comes before something with the order "b" or "c". The "-" or "[]" structures that can be found in vanilla order strings do not have any special meaning.

Advanced

When the game compares 2 like prototypes if the order strings aren't equal they're lexicographically compared to determine if a given prototype comes before or after another. When the order strings are equal the game then falls back to comparing the prototype names to determine order.

Examples

Two item prototypes

The second item is shown before the first one (in the crafting grid/inventory etc)

{
    type = "item",
    name = "item-1",
    order = "ad",
  },

  {
    type = "item",
    name = "item-2",
    order = "ab",
  },

Some sorted strings

Using a UTF-8 character list, the sort order of special characters can identified, here the sort order for common characters:

  • "-"
  • "0"
  • "9"
  • "A"
  • "Z"
  • "["
  • "]"
  • "a"
  • "z"

Example using the above ordering:

  • "a"
  • "ab"
  • "azaaa" (b is sorted before z, so "ab" comes before "az", regardless of the rest of the letters after "az")
  • "b"
  • "b-zzzz"
  • "b[aaaa]" ([ is sorted after - in UTF-8)
  • "bb" (b is sorted after [ in UTF-8)