Control Stage Functions
Pages 3
Clone this wiki locally
script/misc
get_distance
calculates the distance in tiles between two positions
- Parameters:
- position1 -> LuaPosition
- position2 -> LuaPosition
- Returns:
- distance -> double
get_distance_squared
calculates the squared distance in tiles between two positions (slightly faster than get_distance)
- Parameters:
- position1 -> LuaPosition
- position2 -> LuaPosition
- Returns:
- distance -> double
ticks_to_timestring
converts ticks into a string in hh:mm:ss format
- Parameters:
- tick -> uint
- Returns:
- time -> string
compare_tables
(shallowly) compares two tables by content
- Parameters:
- table1, table2
- Returns:
- bool
format_version
converts arbitrary version string X.Y.Z into xx.yy.zz for comparison
- Parameters:
- version -> string
- Returns:
- formatted version -> string
script/train
get_main_locomotive
find main locomotive in a given train
- Parameters:
- train -> LuaTrain
- Returns:
- locomotive -> LuaEntity
get_train_name
find main locomotive name in a given train
- Parameters:
- train -> LuaTrain
- Returns:
- name -> string
rotate_carriage
rotates a single carriage of a train
- Parameters:
- carriage -> LuaEntity
- Returns:
- true if rotated successful
get_train_composition_string
creates string representing train composition.
L for locomotives, C for cargo wagons, F for fluid wagons, A for artillery wagon
- Parameters:
- train-> LuaTrain
- Returns:
- string
open_train_gui
opens train GUI for given player
- Parameters:
- player_index -> uint
- train -> LuaTrain
- Returns:
- true if successful
script/logger
Adds customized log, print and tostring functions. To import the logger module, add this code to your mod, use:
logger = require("__OpteraLib__.script.logger")
To import a single function, use:
my_log = require("__OpteraLib__.script.logger").log
log
Takes a variable number of arguments of any type. Arguments are converted into a human-readable string, concatenated and written to factorio_current.log. The logged message is pre-pended with the file and line from which custom_log was called.
- Parameters
- any number of arguments of any type
- Returns
- logged_message -> string
Takes a variable number of arguments of any type. Arguments are converted into a human-readable string, concatenate and printed to Factorios ingame console for every player.
- Parameters
- any number of arguments of any type
- Returns
- printed_message -> string
tostring
Takes a variable number of arguments of any type. Arguments are converted into a human-readable string, concatenate and returned.
- Parameters
- any number of arguments of any type
- Returns
- message -> string
add_debug_commands
Adds three new console commands: /global_log, /global_print and /wipe_ui.
- /global_log [sub.table]: Writes global table to log file. To only write parts of the global table, specify the sub tables as a single string, with each level separated by a dot.
- /global_print [sub.table]: Same as global_log, but prints to console.
- /wipe_ui [position]: Deletes all modded UI elements. Can be called with [position] parameter (left/center/top) to delete only elements attached to the specified GUI root element.
- Usage example:
/global_print data.mytable
settings
A table with keys max_depth, read_all_properties and class_dictionary'.
max_depth(default = 5) sets how many levels of nested tables or objects are converted to string.
read_all_properties(default = false) makes logger ignore the class dictionary and try to convert all properties of Factorio objects. WARNING this setting can produces _huge_ log files. When used with increase 'max_depth' it can lock up your game for a few seconds on each call. Use with caution and only in developer builds of your mod.
class_dictionary is used to tell logger which Factorio objects to convert to string. The syntax and composition of the dictionary is explained in comments in the .lua file
- Usage example:
logger.settings.class_dictionary.LuaItemStack = {
type = true,
count = true,
valid = true,
valid_for_read = true,
}