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 battle
Loaded in Campaign loaded in campaign
Loaded in Frontend loaded in frontend
Back to top

Creation

script_messager:new()

Gets or creates a script_messager object.

Returns:

  1. script_messager

defined in ../working_data/script/_lib/lib_script_messager.lua, line 52

Back to top

Usage

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
)
Back to top

Debugging

script_messager:output()

Outputs the script_messager internal data for debug purposes.

Returns:

  1. 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:

  1. nil

defined in ../working_data/script/_lib/lib_script_messager.lua, line 139

Back to top

Messages

script_messager:add_listener(string message name, function callback to call, [boolean persistent])

Adds a listener for a message. If the specified message is received, the specified callback is called. If the third parameter is set to true then the listener will continue after it calls the callback and will listen indefinitely.

Parameters:

1

string

message name

2

function

callback to call

3

boolean

optional, default value=false

persistent

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_script_messager.lua, line 164

script_messager:trigger_message(string message 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

string

message name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_script_messager.lua, line 196

script_messager:remove_listener(string message name)

Removes any listener listening for a particular message.

Parameters:

1

string

message name

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_script_messager.lua, line 257

script_messager:block_message(string message name, [boolean should 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_message is called.

Parameters:

1

string

message name

2

boolean

optional, default value=true

should block

Returns:

  1. nil

defined in ../working_data/script/_lib/lib_script_messager.lua, line 276

Last updated 25/08/2021 12:07:50