Skip to content

Fabric

Overview

The Fabric section in the cee API provides functions for interacting with and managing computer-to-computer communication across linked gold-pin networks, enabling direct peer discovery and network messaging in a ComputerCraft/CC:Tweaked environment.

This section is essential for developers working on distributed computer networks, peer-to-peer messaging, and cross-system event broadcasting. The functions provided allow for fine-grained control over how programs communicate with other computers on the same fabric.


Calling Conventions / Prefixes

All methods within the Fabric section are accessed through the global cee namespace, meaning they can be invoked directly as:

local peers = cee.fabricPeers()
cee.fabricBroadcast("Hello Fabric")

These functions do not require any object instantiation and operate on the current network fabric state. They should not be confused with methods that are part of other sections like speaker or monitor, which may have their own peripheral handles.


API Reference Table

Signature Arguments & Types Description
cee.fabricPeers() None Modules linked gold to gold.
cee.fabricSend(id, message) id (number), message (any) Event cee_fabric_message(id, msg).
cee.fabricBroadcast(message) message (any) The same, to every other computer.

Lua Code Examples

Example 1: Listing Fabric Peers

local peers = cee.fabricPeers()
print("Connected fabric peers count:", #peers)
for _, computerId in ipairs(peers) do
    print("Peer computer ID:", computerId)
end

Example 2: Sending a Message to a Specific Peer

local targetId = 2
local message = "Direct command from master computer"
local deliveredCount = cee.fabricSend(targetId, message)
print("Message delivered to", deliveredCount, "peer(s).")

Example 3: Broadcasting to All Fabric Peers

local message = { type = "status_update", state = "active" }
local totalDelivered = cee.fabricBroadcast(message)
print("Broadcast sent to", totalDelivered, "computers.")

Example 4: Listening for Fabric Messages in a Loop

print("Listening for incoming fabric messages...")
while true do
    local _, senderId, msg = os.pullEvent("cee_fabric_message")
    print("Received message from computer ID:", senderId)
    print("Message content:", textutils.serialise(msg))
end

Example 5: Conditional Peer Communication

local peers = cee.fabricPeers()
if #peers > 0 then
    cee.fabricBroadcast("System online and ready.")
else
    print("No fabric peers detected.")
end

Notes

  • cee.fabricPeers() returns a list of computer IDs linked together via gold-pin connections.
  • cee.fabricSend() and cee.fabricBroadcast() both trigger the cee_fabric_message(id, msg) event on receiving computers.
  • Both sending functions return the number of computers that successfully received the message.