Script Messager
The script messager is a lightweight object designed to allow separate script systems to send and listen for string messages. It is very much like a cut-down event system, without the congestion of events that are naturally triggered by the game. Its main purpose is to underpin the mechanics of the generated_battle system.
Unlike the events system, the script messager supports the blocking of messages, so that one bit of script can prevent the transmission of a specific message by any other bit of script.
It is rare to need to get a handle to a script messager object directly, as the generated_battle system stores an internal reference to it and calls it automatically when necessary.
| Loaded in Battle |
|
| Loaded in Campaign |
|
| Loaded in Frontend |
|
-
script_messager:new() -
Gets or creates a
script_messagerobject.Returns:
script_messager
defined in ../working_data/script/_lib/lib_script_messager.lua, line 52
Once an script_messager object has been created with script_messager:new, functions on it may be called in the form showed below.
Example - Specification:
<script_messager_object>:<function_name>(<args>)
Example - Creation and Usage:
local sm = script_messager:new() -- set up automatically by campaign or battle managers
sm:add_listener( -- calling a function on the object once created
"test_message",
function() out("* test_message received") end
)
-
script_messager:output() -
Outputs the script_messager internal data for debug purposes.
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 120
-
script_messager:set_debug() -
Sets the script_messager into debug mode for added output.
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 139
-
script_messager:add_listener(stringmessage name, functioncallback to call, [booleanpersistent]) -
Adds a listener for a message. If the specified message is received, the specified callback is called. If the third parameter is set to
truethen the listener will continue after it calls the callback and will listen indefinitely.Parameters:
1
stringmessage name
2
functioncallback to call
3
booleanoptional, default value=false
persistent
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 164
-
script_messager:trigger_message(stringmessage name) -
Triggers a string message. Prompts the messager system to notify any listeners for the subject message and call the callback they registered.
Parameters:
1
stringmessage name
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 196
-
script_messager:remove_listener(stringmessage name) -
Removes any listener listening for a particular message.
Parameters:
1
stringmessage name
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 257
-
script_messager:block_message(stringmessage name, [booleanshould block]) -
Blocks or unblocks a message from being transmitted in the future. If a message is blocked, no listeners will be notified when
script_messager:trigger_messageis called.Parameters:
1
stringmessage name
2
booleanoptional, default value=true
should block
Returns:
nil
defined in ../working_data/script/_lib/lib_script_messager.lua, line 276