Linking Entities

Overview

In Sandbox, it is possible to link an entity to other entities. More information on this feature can be found in the Sandbox Manual under Grouping and Linking Objects.

These links are organized inside the Entity System. Each entity can link to multiple entities. Each link has a name associated to it.

Script Example

The following Lua script will gather from the entity system any link to other entity which is named "Generator".

function RadarBase:IsPowered()
  local i=0;
  local link = self:GetLinkTarget("Generator", i);
  
  while (link) do
    Log("Generator %s", link:GetName());
    
    if (link:GetState() == "PowerOn") then
      if (link.PowerConnect) then
        link:PowerConnect(self.id);
        return true;
      end
    end
    
    i=i+1;
    link=self:GetLinkTarget("Generator", i);
  end
  
  return false;
end

Script Functions

The ScriptBind functions related to Entity Links are listed in ScriptBind_Entity.

The following functions will read or create entity links:

  • CountLinks
  • CreateLink
  • GetLink
  • GetLinkName
  • GetLinkTarget
  • RemoveAllLinks
  • RemoveLink
  • SetLinkTarget