Helpful Functions - Silverfeelin/Starbound-MessageHandling-Demo GitHub Wiki

The messageutil script contains various helper functions that'll make writing message handlers easier, and will help keep track of asynchronous message responses.

To use it, simply require it in your script.

require "/scripts/messageutil.lua"

Functions

• simpleHandler(func)

Wraps a function as a message handler. The function will always be called, ignoring the first two arguments (messageName, isLocal).

This handler can be called by anyone, even remote clients.

Example

Both implementations accomplish the same, but the simple handler only has a data parameter.

require "/scripts/messageutil.lua"

function init()
  message.setHandler("normalHandler", normalMessageHandler)
  message.setHandler("simpleHandler", simpleHandler(simpleMessageHandler))
end

function normalMessageHandler(message, local, someParam)
  --[ Code ](/Silverfeelin/Starbound-MessageHandling-Demo/wiki/-Code-)
end

function simpleMessageHandler(someParam)
  --[ Code ](/Silverfeelin/Starbound-MessageHandling-Demo/wiki/-Code-)
end

• localHandler(func)

Wraps a function as a message handler. The function will only be called if the isLocal argument is true.

This handler can only be called locally (player scripts, interfaces, managed projectiles).

Example

Both implementations accomplish the same, but the local handler only has a data parameter. The normal handler on the other hand has to manually filter out entities that aren't local.

require "/scripts/messageutil.lua"

function init()
  message.setHandler("normalHandler", normalMessageHandler)
  message.setHandler("simpleHandler", localHandler(localMessageHandler))
end

function normalMessageHandler(message, localEntity, someParam)
  if not localEntity then return end

  --[ Code ](/Silverfeelin/Starbound-MessageHandling-Demo/wiki/-Code-)
end

function localMessageHandler(someParam)
  --[ Code ](/Silverfeelin/Starbound-MessageHandling-Demo/wiki/-Code-)
end