mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 19:45:22 +09:00
569 lines
18 KiB
HTML
569 lines
18 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
|
<head>
|
|
<title>Reference</title>
|
|
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
|
|
<div id="container">
|
|
|
|
<div id="product">
|
|
<div id="product_logo"></div>
|
|
<div id="product_name"><big><b></b></big></div>
|
|
<div id="product_description"></div>
|
|
</div> <!-- id="product" -->
|
|
|
|
|
|
<div id="main">
|
|
|
|
|
|
<!-- Menu -->
|
|
|
|
<div id="navigation">
|
|
<br/>
|
|
<h1>ldoc</h1>
|
|
|
|
<ul>
|
|
<li><a href="../index.html">Index</a></li>
|
|
</ul>
|
|
|
|
<h2>Contents</h2>
|
|
<ul>
|
|
<li><a href="#Functions">Functions</a></li>
|
|
</ul>
|
|
|
|
|
|
<h2>Modules</h2>
|
|
<ul class="$(kind=='Topics' and '' or 'nowrap'">
|
|
<li><a href="../modules/config._file_loader.html">config._file_loader</a></li>
|
|
<li><a href="../modules/config.action_buttons.html">config.action_buttons</a></li>
|
|
<li><a href="../modules/config.advanced_start.html">config.advanced_start</a></li>
|
|
<li><a href="../modules/config.death_logger.html">config.death_logger</a></li>
|
|
<li><a href="../modules/config.expcore-commands.auth_admin.html">config.expcore-commands.auth_admin</a></li>
|
|
<li><a href="../modules/config.expcore-commands.auth_roles.html">config.expcore-commands.auth_roles</a></li>
|
|
<li><a href="../modules/config.expcore-commands.auth_runtime_disable.html">config.expcore-commands.auth_runtime_disable</a></li>
|
|
<li><a href="../modules/config.expcore-commands.parse_general.html">config.expcore-commands.parse_general</a></li>
|
|
<li><a href="../modules/config.expcore-commands.parse_roles.html">config.expcore-commands.parse_roles</a></li>
|
|
<li><a href="../modules/config.permission_groups.html">config.permission_groups</a></li>
|
|
<li><a href="../modules/config.popup_messages.html">config.popup_messages</a></li>
|
|
<li><a href="../modules/config.rockets.html">config.rockets</a></li>
|
|
<li><a href="../modules/config.roles.html">config.roles</a></li>
|
|
<li><a href="../modules/config.scorched_earth.html">config.scorched_earth</a></li>
|
|
<li><a href="../modules/config.spawn_area.html">config.spawn_area</a></li>
|
|
<li><a href="../modules/config.warnings.html">config.warnings</a></li>
|
|
<li><a href="../modules/control.html">control</a></li>
|
|
<li><a href="../modules/Commands.html">Commands</a></li>
|
|
<li><a href="../modules/Public.html">Public</a></li>
|
|
<li><a href="../modules/expcore.gui.html">expcore.gui</a></li>
|
|
<li><a href="../modules/expcore.gui.buttons.html">expcore.gui.buttons</a></li>
|
|
<li><a href="../modules/expcore.gui.center.html">expcore.gui.center</a></li>
|
|
<li><a href="../modules/expcore.gui.checkboxs.html">expcore.gui.checkboxs</a></li>
|
|
<li><a href="../modules/expcore.gui.core.html">expcore.gui.core</a></li>
|
|
<li><a href="../modules/expcore.gui.dropdown.html">expcore.gui.dropdown</a></li>
|
|
<li><a href="../modules/expcore.gui.elem-button.html">expcore.gui.elem-button</a></li>
|
|
<li><a href="../modules/expcore.gui.instances.html">expcore.gui.instances</a></li>
|
|
<li><a href="../modules/expcore.gui.left.html">expcore.gui.left</a></li>
|
|
<li><a href="../modules/expcore.gui.popups.html">expcore.gui.popups</a></li>
|
|
<li><a href="../modules/expcore.gui.progress-bar.html">expcore.gui.progress-bar</a></li>
|
|
<li><a href="../modules/expcore.gui.slider.html">expcore.gui.slider</a></li>
|
|
<li><a href="../modules/expcore.gui.test.html">expcore.gui.test</a></li>
|
|
<li><a href="../modules/expcore.gui.text.html">expcore.gui.text</a></li>
|
|
<li><a href="../modules/expcore.gui.toolbar.html">expcore.gui.toolbar</a></li>
|
|
<li><a href="../modules/Permissions_Groups.html">Permissions_Groups</a></li>
|
|
<li><a href="../modules/Commands.html">Commands</a></li>
|
|
<li><a href="../modules/expcore.store.html">expcore.store</a></li>
|
|
<li><a href="../modules/modules.addons.advanced-start.html">modules.addons.advanced-start</a></li>
|
|
<li><a href="../modules/modules.addons.chat-popups.html">modules.addons.chat-popups</a></li>
|
|
<li><a href="../modules/modules.addons.damage-popups.html">modules.addons.damage-popups</a></li>
|
|
<li><a href="../modules/modules.gui.player-list.html">modules.gui.player-list</a></li>
|
|
<li><a href="../modules/modules.gui.rocket-info.html">modules.gui.rocket-info</a></li>
|
|
<li><a href="../modules/modules.gui.science-info.html">modules.gui.science-info</a></li>
|
|
<li><a href="../modules/modules.gui.task-list.html">modules.gui.task-list</a></li>
|
|
<li><a href="../modules/utils.alien_evolution_progress.html">utils.alien_evolution_progress</a></li>
|
|
<li><a href="../modules/utils.core.html">utils.core</a></li>
|
|
<li><a href="../modules/utils.debug.html">utils.debug</a></li>
|
|
<li><strong>utils.event</strong></li>
|
|
<li><a href="../modules/utils.event_core.html">utils.event_core</a></li>
|
|
<li><a href="../modules/utils.math.html">utils.math</a></li>
|
|
<li><a href="../modules/utils.recipe_locker.html">utils.recipe_locker</a></li>
|
|
<li><a href="../modules/utils.state_machine.html">utils.state_machine</a></li>
|
|
<li><a href="../modules/utils.table.html">utils.table</a></li>
|
|
<li><a href="../modules/utils.task.html">utils.task</a></li>
|
|
<li><a href="../modules/utils.timestamp.html">utils.timestamp</a></li>
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
<div id="content">
|
|
|
|
<h1>Module <code>utils.event</code></h1>
|
|
<p>This Module allows for registering multiple handlers to the same event, overcoming the limitation of script.register.</p>
|
|
<p>
|
|
<p> ** Event.add(event_name, handler) **
|
|
<p> Handlers added with Event.add must be added at the control stage or in Event.on_init or Event.on_load.
|
|
Remember that for each player, on_init or on_load is run, never both. So if you can't add the handler in the
|
|
control stage add the handler in both on_init and on_load.
|
|
Handlers added with Event.add cannot be removed.
|
|
For handlers that need to be removed or added at runtime use Event.add_removable.</p>
|
|
<h3>Usage:</h3>
|
|
<ul>
|
|
<li><pre class="example">
|
|
local Event = require 'utils.event'
|
|
Event.add(
|
|
defines.events.on_built_entity,
|
|
function(event)
|
|
game.print(serpent.block(event)) -- prints the content of the event table to console.
|
|
end
|
|
)
|
|
|
|
** Event.add_removable(event_name, token) **
|
|
|
|
For conditional event handlers. Event.add_removable can be safely called at runtime without desync risk.
|
|
Only use this if you need to add the handler at runtime or need to remove the handler, otherwise use Event.add
|
|
|
|
Event.add_removable can be safely used at the control stage or in Event.on_init. If used in on_init you don't
|
|
need to also add in on_load (unlike Event.add).
|
|
Event.add_removable cannot be called in on_load, doing so will crash the game on loading.
|
|
Token is used because it's a desync risk to store closures inside the global table.
|
|
</pre></li>
|
|
<li><pre class="example">
|
|
local Token = require 'utils.token'
|
|
local Event = require 'utils.event'
|
|
|
|
Token.register must not be called inside an event handler.
|
|
local handler =
|
|
Token.register(
|
|
function(event)
|
|
game.print(serpent.block(event)) -- prints the content of the event table to console.
|
|
end
|
|
)
|
|
|
|
The below code would typically be inside another event or a custom command.
|
|
Event.add_removable(defines.events.on_built_entity, handler)
|
|
|
|
When you no longer need the handler.
|
|
Event.remove_removable(defines.events.on_built_entity, handler)
|
|
|
|
It's not an error to register the same token multiple times to the same event, however when
|
|
removing only the first occurrence is removed.
|
|
|
|
** Event.add_removable_function(event_name, func) **
|
|
|
|
Only use this function if you can't use Event.add_removable. i.e you are registering the handler at the console.
|
|
The same restrictions that apply to Event.add_removable also apply to Event.add_removable_function.
|
|
func cannot be a closure in this case, as there is no safe way to store closures in the global table.
|
|
A closure is a function that uses a local variable not defined in the function.
|
|
</pre></li>
|
|
<li><pre class="example">
|
|
local Event = require 'utils.event'
|
|
|
|
If you want to remove the handler you will need to keep a reference to it.
|
|
global.handler = function(event)
|
|
game.print(serpent.block(event)) -- prints the content of the event table to console.
|
|
end
|
|
|
|
The below code would typically be used at the command console.
|
|
Event.add_removable_function(defines.events.on_built_entity, global.handler)
|
|
|
|
When you no longer need the handler.
|
|
Event.remove_removable_function(defines.events.on_built_entity, global.handler)
|
|
|
|
** Other Events **
|
|
|
|
Use Event.on_init(handler) for script.on_init(handler)
|
|
Use Event.on_load(handler) for script.on_load(handler)
|
|
|
|
Use Event.on_nth_tick(tick, handler) for script.on_nth_tick(tick, handler)
|
|
Favour this event over Event.add(defines.events.on_tick, handler)
|
|
There are also Event.add_removable_nth_tick(tick, token) and Event.add_removable_nth_tick_function(tick, func)
|
|
That work the same as above.
|
|
|
|
** Custom Scenario Events **
|
|
|
|
local Event = require 'utils.event'
|
|
|
|
local event_id = script.generate_event_name()
|
|
|
|
Event.add(
|
|
event_id,
|
|
function(event)
|
|
game.print(serpent.block(event)) -- prints the content of the event table to console.
|
|
end
|
|
)
|
|
|
|
The table contains extra information that you want to pass to the handler.
|
|
script.raise_event(event_id, {extra = 'data'})</pre></li>
|
|
</ul>
|
|
|
|
|
|
<h2><a href="#Functions">Functions</a></h2>
|
|
<table class="function_list">
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.add">Event.add (event_name, handler)</a></td>
|
|
<td class="summary">Register a handler for the event_name event.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.on_init">Event.on_init (handler)</a></td>
|
|
<td class="summary">Register a handler for the script.on_init event.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.on_load">Event.on_load (handler)</a></td>
|
|
<td class="summary">Register a handler for the script.on_load event.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.on_nth_tick">Event.on_nth_tick (tick, handler)</a></td>
|
|
<td class="summary">Register a handler for the nth_tick event.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.add_removable">Event.add_removable (event_name, token)</a></td>
|
|
<td class="summary">Register a token handler that can be safely added and removed at runtime.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.remove_removable">Event.remove_removable (event_name, token)</a></td>
|
|
<td class="summary">Removes a token handler for the given event_name.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.add_removable_function">Event.add_removable_function (event_name, func)</a></td>
|
|
<td class="summary">Register a handler that can be safely added and removed at runtime.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.remove_removable_function">Event.remove_removable_function (event_name, func)</a></td>
|
|
<td class="summary">Removes a handler for the given event_name.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.add_removable_nth_tick">Event.add_removable_nth_tick (tick, token)</a></td>
|
|
<td class="summary">Register a token handler for the nth tick that can be safely added and removed at runtime.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.remove_removable_nth_tick">Event.remove_removable_nth_tick (tick, token)</a></td>
|
|
<td class="summary">Removes a token handler for the nth tick.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.add_removable_nth_tick_function">Event.add_removable_nth_tick_function (tick, func)</a></td>
|
|
<td class="summary">Register a handler for the nth tick that can be safely added and removed at runtime.</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name" nowrap><a href="#Event.remove_removable_nth_tick_function">Event.remove_removable_nth_tick_function (tick, func)</a></td>
|
|
<td class="summary">Removes a handler for the nth tick.</td>
|
|
</tr>
|
|
</table>
|
|
|
|
<br/>
|
|
<br/>
|
|
|
|
|
|
<h2><a name="Functions"></a>Functions</h2>
|
|
|
|
<dl class="function">
|
|
<dt>
|
|
<a name = "Event.add"></a>
|
|
<strong>Event.add (event_name, handler)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler for the event_name event.
|
|
This function must be called in the control stage or in Event.on_init or Event.on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">event_name</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">handler</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.on_init"></a>
|
|
<strong>Event.on_init (handler)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler for the script.on_init event.
|
|
This function must be called in the control stage or in Event.on_init or Event.on_load
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">handler</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.on_load"></a>
|
|
<strong>Event.on_load (handler)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler for the script.on_load event.
|
|
This function must be called in the control stage or in Event.on_init or Event.on_load
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">handler</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.on_nth_tick"></a>
|
|
<strong>Event.on_nth_tick (tick, handler)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler for the nth_tick event.
|
|
This function must be called in the control stage or in Event.on_init or Event.on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">tick</span>
|
|
<number> The handler will be called every nth tick
|
|
</li>
|
|
<li><span class="parameter">handler</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.add_removable"></a>
|
|
<strong>Event.add_removable (event_name, token)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a token handler that can be safely added and removed at runtime.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">event_name</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">token</span>
|
|
<number>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.remove_removable"></a>
|
|
<strong>Event.remove_removable (event_name, token)</strong>
|
|
</dt>
|
|
<dd>
|
|
Removes a token handler for the given event_name.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">event_name</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">token</span>
|
|
<number>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.add_removable_function"></a>
|
|
<strong>Event.add_removable_function (event_name, func)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler that can be safely added and removed at runtime.
|
|
The handler must not be a closure, as that is a desync risk.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">event_name</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">func</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.remove_removable_function"></a>
|
|
<strong>Event.remove_removable_function (event_name, func)</strong>
|
|
</dt>
|
|
<dd>
|
|
Removes a handler for the given event_name.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">event_name</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">func</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.add_removable_nth_tick"></a>
|
|
<strong>Event.add_removable_nth_tick (tick, token)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a token handler for the nth tick that can be safely added and removed at runtime.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">tick</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">token</span>
|
|
<number>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.remove_removable_nth_tick"></a>
|
|
<strong>Event.remove_removable_nth_tick (tick, token)</strong>
|
|
</dt>
|
|
<dd>
|
|
Removes a token handler for the nth tick.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">tick</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">token</span>
|
|
<number>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.add_removable_nth_tick_function"></a>
|
|
<strong>Event.add_removable_nth_tick_function (tick, func)</strong>
|
|
</dt>
|
|
<dd>
|
|
Register a handler for the nth tick that can be safely added and removed at runtime.
|
|
The handler must not be a closure, as that is a desync risk.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">tick</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">func</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
<dt>
|
|
<a name = "Event.remove_removable_nth_tick_function"></a>
|
|
<strong>Event.remove_removable_nth_tick_function (tick, func)</strong>
|
|
</dt>
|
|
<dd>
|
|
Removes a handler for the nth tick.
|
|
Do NOT call this method during on_load.
|
|
See documentation at top of file for details on using events.
|
|
|
|
|
|
<h3>Parameters:</h3>
|
|
<ul>
|
|
<li><span class="parameter">tick</span>
|
|
<number>
|
|
</li>
|
|
<li><span class="parameter">func</span>
|
|
<function>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
|
|
</div> <!-- id="content" -->
|
|
</div> <!-- id="main" -->
|
|
<div id="about">
|
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.3</a></i>
|
|
<i style="float:right;">Last updated 2019-05-29 22:22:59 </i>
|
|
</div> <!-- id="about" -->
|
|
</div> <!-- id="container" -->
|
|
</body>
|
|
</html>
|