Skip to main content

Starting Out

warning

This guide assumes a basic level of luau programming ability and Waste of Space knowledge!

Wiring

To allow your code to interact with the game world, you must first obtain a PilotObject instance. To do this, first make sure that you have connected the part to the Microcontroller using a Port or a direct connection (see Figure 1).


You can also extend the range of the microcontroller / ports by using EthernetCable(s) (see Figure 2).


If your build requires connections which are not practical to link with wiring, you can use Routers as a wireless bridge (see Figure 3).

API

There are four main methods for getting parts: Network:GetPart, Network:GetParts, Network:GetPartFromPort, and Network:GetPartsFromPort. The plural variations will return an array instead of a single part. These methods are global in all microcontroller code execution sandboxes.

  • Network:GetPart(s) will look through parts that are directly connected but not through ports.

  • Network:GetPart(s)FromPort will only look through parts that are connected through ports.

These two special methods Network:GetPort and Network:GetPorts will return the port of the specified PortID, looking through all ports which are directly connected.

For more documentation on ethernet networks: /types/Network

Function signatures:

  • Network:GetPartFromPort(Port | number, string) → PilotObject Gets a part of the specified type from any port of the specified ID.

  • Network:GetPartsFromPort(Port | number, string) → {PilotObject} Gets all the parts of the specified type from any port of the specified ID.

  • Network:GetPart(string) → PilotObject Gets a part of the specified type from any connected parts.

  • Network:GetParts(string) → {PilotObject} Gets all the parts of the specified type from any connected parts.

  • Network:GetPort(number) → Port Gets the connected port of the specified ID.

  • Network:GetPorts(number?) → {Port} Gets all the connected ports of the specified ID. If no ID is specified it will get all connected ports.

Note that once your code stops running and you have not binded any event listeners, the microcontroller will shut off. This can be an issue when making UI, as the game will delete your UI elements, and can be alleviated by simply adding coroutine.yield() at the end of your code. This is explained in more detail in keeping your microcontroller enabled

Examples

-- Examples
-- This code will work with all figures 1-3
local switch = Network:GetPart("Switch")
local microphone = Network:GetPartFromPort(1, "Microphone")

-- Alternatively, you can pass in a Port into GetPart(s)FromPort:
local port = Network:GetPort(1)
local microphone = Network:GetPartFromPort(port, "Microphone")

It is recommended to use assert as to avoid wiring issues. This means if for whatever reason your code failed to find the switch or microphone, it would give you an error and directly say "no microphone".

local switch = assert(Network:GetPart("Switch"), "no switch")
local microphone = assert(Network:GetPartFromPort(1, "Microphone"), "no microphone")