Force global creation.
Requiring this module will register init and force creation events using the stdlib Event module.
All existing and new players will be added to the global.forces
table.
This module should be first required after any other Init functions but before any scripts needing global.players
.
This module registers the following events: on_init
, on_configuration_changed
, on_player_created
, and on_player_removed
.
local Force = require 'stdlib/event/force'
-- The fist time this is required it will register force creation events
add_data_all (data) | Merge a copy of the passed data to all forces in global.forces . |
get (force) | Get game.forces[name] & global.forces[name] , or create global.forces[name] if it doesn't exist. |
init ([event][, overwrite=false]) | Init or re-init a force or forces. |
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)
Get game.forces[name]
& global.forces[name]
, or create global.forces[name]
if it doesn't exist.
Parameters: Returns: Usage:
local Force = require '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