LogoLogo
  • Introduction
  • sdks
    • Feature Comparison
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Quick Start
    • Unity
    • Godot
    • Defold
    • LÖVE
    • Unreal
  • Server Side
    • Entities
    • Chunks
    • Dimensions
    • Events
    • Logging
    • Lua Environment
    • Git Primer
    • Physics
  • HTTP API
    • Authentication
    • Player API
  • Api Reference
    • Entity API
      • Create
      • Message
    • Client API
      • Message
    • Dimension API
      • Create
      • Delete
      • List
    • Events API
      • on_player_join
      • on_player_leave
    • Table API
      • Append
      • Remove
      • Join
    • Util API
      • Time
      • TimeMillis
    • HTTP Request API
      • Get
      • Post
      • Put
      • Delete
    • Physics API
      • NewBody
      • NewBoxShape
      • NewSphereShape
Powered by GitBook
On this page
  1. Api Reference
  2. Entity API

Message

api.entity.Message(entityid, message)

Sends a message to an entity.

This message can be sent to an entity anywhere in the world, if it exists.

Parameters:

Name
Type
Description

entityid

string

The ID of the entity, to send the message to.

message

table

The Data being conveyed.

Example:

Send messages to nearby cat and tree entities.

-- entity_type_name.lua
local function update(self, dt)    
    local entity_list = self:GetNearbyEntities(5)
    
    for id, entity in pairs(entity_list) do
        local message = {
            words = "Hello "..entity.Type.."!",
            action = "pet",
            from = self.Type
        }
        api.entity.Message(entity.ID, message)
    end
end
    
-- cat.lua
local function message(self, msg)
    if msg.Data.from == "entity_type_name" then
        print(msg.Data.words)
        print("The cat has been "..msg.Data.action..". It goes \"Meow\".")
    end
end
    
--tree.lua
local function message(self, msg)
    if msg.Data.from == "entity_type_name" then
        print(msg.Data.words)
        print("The tree has been "..msg.Data.action..". It does not respond.")
    end
end

-- Whenever an entity_type_name comes within 5 world units of a cat or tree, 
-- send a message to all entities nearby.
-- Print the details of the message from whichever entities received it.

-- Prints:
-- Hello cat!
-- The cat has been pet. It goes Meow.

-- Or Prints:
-- Hello tree!
-- The tree has been pet. It does not respond.

PreviousCreateNextClient API

Last updated 3 months ago