table_util¶
Source: base/tealdef/scripts/table_util.d.tl
Notes
Types of /scripts/table_util.tl (TableUtil): deep comparison and copying of tables and simple
array search helpers. Load it with local table_util = ug_require "/scripts/table_util.tl" as TableUtil.
TableUtil¶
record global base/tealdef/scripts/table_util.d.tl:3
global record TableUtil
Load: local table_util = ug_require "::/scripts/table_util.tl" as TableUtil
Notes
Table helpers returned by ug_require "/scripts/table_util.tl".
Functions
deepEquals(arg1 : any, arg2 : any, allowFunctions? : boolean, key? : any) : boolean base/tealdef/scripts/table_util.d.tl:4
Call as table_util.deepEquals(…)
Notes
Recursively compares two values; tables are equal when they have the same keys with deeply equal values.
| Parameter | Type | Description |
|---|---|---|
arg1 |
any |
First value. |
arg2 |
any |
Second value. |
allowFunctions? |
boolean |
If true, functions are compared by identity. Otherwise comparing functions logs an error, unless both tables carry a <key>_compareProxy sibling value (compared instead) or the key ends in ecipe. |
key? |
any |
Key under which the values are stored; used for function comparison and error messages. |
Returns boolean: True if the values are deeply equal.
Details
Userdata values must implement an equals method; it is called for the comparison.
Used in the base game: 140 times in 50 files
base/content/base/base/difficulty_util.tl:213
base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:501
base/content/game_mechanics/game_mechanics/company/company_react_util.tl:180
base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:50
base/content/game_mechanics/game_mechanics/notifications/notification_util.tl:229
base/content/game_mechanics/game_mechanics/towns/town_growth.script.tl:185
… and 44 more files.
copy<T>(obj : T) : T base/tealdef/scripts/table_util.d.tl:5
Call as table_util.copy(…)
Notes
Deep copy of a table (keys and values copied recursively); non-table values are returned unchanged.
Returns T
Details
Metatables are not copied, so vectors from vec3.new lose their operators.
Used in the base game: 238 times in 67 files
base/content/climates/climates/gen/mapgenutil.tl:126
base/content/game_mechanics/game_mechanics/celebrations/celebration_react_util.tl:155
base/content/game_mechanics/game_mechanics/company/company.script.tl:29
base/content/game_mechanics/game_mechanics/finance/finances_react_util.tl:194
base/content/game_mechanics/game_mechanics/fun_elements/fireworks.script.tl:71
base/content/game_mechanics/game_mechanics/notifications/gui/notification_log.tl:384
… and 61 more files.
shallowCopy<T>(obj : T) : T base/tealdef/scripts/table_util.d.tl:6
Call as table_util.shallowCopy(…)
Notes
Copies the top-level key/value pairs of a table into a new table; nested tables are shared.
Returns T
Used in the base game: 67 times in 20 files
base/content/game_mechanics/game_mechanics/finance/finances_charts.tl:48
base/content/gui/gui/construction/construction.tl:1321
base/content/gui/gui/construction/construction_react_util.tl:4045
base/content/gui/gui/entity_window/bridge_and_tunnel.tl:105
base/content/gui/gui/entity_window/industry/industry.tl:285
base/content/gui/gui/entity_window/make_entity_window.tl:259
… and 14 more files.
arrayFind<T>(arr : {T}, value : T) : integer base/tealdef/scripts/table_util.d.tl:7
Call as table_util.arrayFind(…)
Notes
Index of the first element equal (==) to value.
Returns integer: The 1-based index, or 0 if the value is not in the array.
Used in the base game: 13 times in 7 files
base/content/gui/gui/entity_window/double_slip_switch.tl:118
base/content/gui/gui/game_bar/game_bar_widgets.tl:353
base/content/gui/gui/main/industry_util.tl:568
base/content/gui/gui/main/town_hud_react_util.tl:16
base/content/gui/gui/menu/mod_manager_react_util.tl:2335
base/content/mission/mission/mission_framework/mission_framework_react.tl:1059
… and 1 more files.
arrayFindIf<T>(arr : {T}, pred : function(T) : boolean) : integer base/tealdef/scripts/table_util.d.tl:8
Call as table_util.arrayFindIf(…)
Notes
Index of the first element for which pred returns true.
Returns integer: The 1-based index, or 0 if no element matches.
Used in the base game: 5 times in 4 files
base/content/game_mechanics/game_mechanics/company/explorations/exploration_plane.script.tl:300
base/content/gui/gui/construction/construction.tl:970
local index = table_util.arrayFindIf(objects, function(object : MenuCategoryUtil.FilterObject) : boolean
base/content/gui/gui/entity_window/bridge_and_tunnel.tl:109
if table_util.arrayFindIf(newState.availableObjects, function(object : MenuCategoryUtil.FilterObject) : boolean
base/content/gui/gui/main/menu_category_util.tl:368
arrayRemove<T>(arr : {T}, value : T) : boolean base/tealdef/scripts/table_util.d.tl:9
Call as table_util.arrayRemove(…)
Notes
Removes the first element equal to value from the array, in place.
Returns boolean: True if an element was removed.
arrayContains<T>(arr : {T}, value : T) : boolean base/tealdef/scripts/table_util.d.tl:10
Call as table_util.arrayContains(…)
Notes
True if the array contains an element equal (==) to value.
Returns boolean
Used in the base game: 104 times in 32 files
base/content/game_mechanics/game_mechanics/achievements/achievements.script.tl:230
if IsDefaultModCargo(cargoName) and not table_util.arrayContains(achievementState.cargoTypesDelivered, cargoName) then
base/content/game_mechanics/game_mechanics/notifications/types/con_availability.script.tl:20
base/content/game_mechanics/game_mechanics/towns/town_growth.script.tl:256
base/content/gui/gui/construction/construction.tl:3350
base/content/gui/gui/construction/construction_react_util.tl:317
base/content/gui/gui/construction/tools/mixed_assets.script.tl:7
… and 26 more files.
find<K, V>(dict : {{K, V}}, key : K) : V base/tealdef/scripts/table_util.d.tl:11
Call as table_util.find(…)
Notes
Looks up key in a list of {key, value} pairs.
Returns V: The value of the first pair whose first element equals key, or nil.
concatenate<T>(...: {T}) : {T} base/tealdef/scripts/table_util.d.tl:12
Call as table_util.concatenate(…)
Notes
Returns a new array with the elements of all given arrays, in order.
Returns {T}
Used in the base game: 28 times in 16 files
base/content/gui/gui/entity_window/industry/industry.tl:300
widgets = table_util.concatenate(widgets, gui_react_util.usePlugins(industry_eow.IndustryEowExtensionPoint, { firstRef = initialFocusRef, }, extensionParams))
base/content/gui/gui/entity_window/vehicle/vehicle_eow.script.tl:139
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/game_bar/game_bar.tl:182
base/content/gui/gui/line_vehicle_mgmt/line_react_util.tl:601
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/manager_window.tl:3600
local colorPalette = color_util.toArray3(table_util.concatenate((api.gui.genericRep.get(api.gui.genericRep.find("::/gui/line_vehicle_mgmt/line_colors.gres")).da
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:275
… and 10 more files.
merge<T, V>(...: {T : V}) : {T : V} base/tealdef/scripts/table_util.d.tl:13
Call as table_util.merge(…)
if same key is in multiple tables, the last one wins.
Returns {T : V}
Used in the base game: 11 times in 3 files
base/content/gui/gui/menu/graphics_presets_util.tl:169
mods/release/urbangames_campaign_mission_02/content/mission/mission/mission_story.tl:80
local allowBuyVehiclesAfterTrainExtension : {string : integer} = table_util.merge(allowBuyVehiclesTrainExtension)
mods/release/urbangames_campaign_mission_05/content/mission/mission/mission_story.tl:527
removeDuplicates<T>(arr : {T}) : {T} base/tealdef/scripts/table_util.d.tl:14
Call as table_util.removeDuplicates(…)
Notes
Returns a new array with repeated elements removed, keeping the first occurrence and the order.
Returns {T}
Used in the base game: 2 times in 2 files
base/content/gui/gui/line_vehicle_mgmt/vehicle_store_util.tl:367
base/content/gui/gui/main/cargo_react_util.tl:709