Force global creation.
All new forces will be added to the global.forces
table.
This modules events should be registered after any other Init functions but before any scripts needing global.players
.
This modules can register the following events: on_force_created
, and on_forces_merging
.
local Force = require('__stdlib__/stdlib/event/force').register_events()
-- inside your Init event Force.init() -- to properly handle any existing forces
get(force) | Get game.forces[name] & global.forces[name] , or create global.forces[name] if it doesn’t exist. |
add_data_all(data) | Merge a copy of the passed data to all forces in global.forces . |
init([event][, overwrite=false]) | Init or re-init a force or forces. |
merged(event) | When forces are merged, just remove the original forces data |
register_events(do_on_init) | Register Events |
Get game.forces[name]
& global.forces[name]
, or create global.forces[name]
if it doesn’t exist.
Parameters: Returns: Usage:
local Force = require('__stdlib__/stdlib/event/force')
local force_name, force_data = Force.get("player")
local force_name, force_data = Force.get(game.forces["player"])
-- Returns data for the force named "player" from either a string or LuaForce object
Merge a copy of the passed data to all forces in global.forces
.
Parameters:
local data = {a = "abc", b = "def"}
Force.add_data_all(data)
Init or re-init a force or forces.
Passing a nil
event will iterate all existing forces.
When forces are merged, just remove the original forces data
Parameters:
Register Events
Parameters: