### Complete Event Handling Example Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/ModularPanelAndEvents.html This comprehensive example demonstrates setting up a panel proxy, getting a button module, clearing and listening for events, and processing button triggers within an event loop. ```lua local panel = component.proxy("...") local btn = panel:getModule(0,0,0) event.ignoreAll() event.clear() event.listen(btn) while true do local e, s = event.pull() if s == btn and e == "Trigger" then print("meep") end end ``` -------------------------------- ### Hello World in Lua Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/TheComponentNetwork.html A basic 'Hello World' example in Lua. This can be used for a quick start or testing the environment. ```lua print("Hello World") ``` -------------------------------- ### startComputer Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/ComputerCase.html Starts the Computer (Processor). ```APIDOC ## startComputer ### Description Starts the Computer (Processor). ### Method Not specified (likely a function call in an SDK) ### Parameters None ### Response #### Success Response None specified. ``` -------------------------------- ### Example Component GUID Source: https://docs.ficsit.app/ficsit-networks/latest/BasicConcept.html A globally unique identifier (GUID) is used to uniquely identify a network component. This is an example of the format. ```plaintext 0123456789abcdef0123456789abcdef ``` -------------------------------- ### Find Component by Nickname and Get Reference Source: https://docs.ficsit.app/ficsit-networks/latest/BasicConcept.html Use `component.findComponent` with a component's nickname to find its GUID, then use `component.proxy` to get a reference. This is more readable than using raw GUIDs. Note that `findComponent` returns an array, and the first element (index 1 in Lua) is used. ```lua constructor = component.proxy(component.findComponent("WireFactory Constructor1")[1]) ``` -------------------------------- ### Efficiently Proxy Single Component Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/AdvancedNetworking.html For performance, it's recommended to filter the UUID array before passing it to `proxy` if only one or a few components are needed. This example shows the fast way to get a single component reference. ```lua local comp1 = component.proxy(component.findComponent("...")[1]) ``` -------------------------------- ### Get Internet Card Reference Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/InternetCard.html Obtain a reference to the installed Internet Card. Use this when you have an Internet Card available. ```lua local card = computer.getPCIDevices(classes.FINInternetCard)[1] ``` -------------------------------- ### Get First Network Card Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/PCIDevices.html Retrieves the first installed network card. It accesses the first element of the table returned by `getPCIDevices` for the NetworkCard class. ```lua local NetworkCard = computer.getPCIDevices(classes.NetworkCard)[1] ``` -------------------------------- ### _computer.getInstance Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Gets a reference to the computer case the current code is running in. ```APIDOC ## _computer.getInstance ### Description Returns a reference to the computer case in which the current code is running. ### Method _computer.getInstance ### Response #### Success Response (200) - **case** (ComputerCase) - The computer case this lua runtime is running in ``` -------------------------------- ### _computer.getPCIDevices Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Retrieves all installed PCI devices, optionally filtered by type. ```APIDOC ## _computer.getPCIDevices ### Description This function allows you to get all installed PCI-Devices in a computer of a given type. ### Method _computer.getPCIDevices ### Parameters #### Query Parameters - **type** (ObjectClass?) - Optional - Optional type which will be used to filter all PCI-Devices. If not provided, will return all PCI-Devices ### Response #### Success Response (200) - **objects** (Object[]) - An array containing instances for each PCI-Device built into the computer ``` -------------------------------- ### Sum Item Counts from Storage Containers Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/AdvancedNetworking.html This example demonstrates how to find all storage containers, proxy them, iterate through them, and sum the `itemCount` from their first inventory. ```lua local containerIDs = component.findComponent(classes.FGBuildableStorage) local containers = component.proxy(containerIDs) local sum = 0 for _, container in ipairs(containers) do sum = sum + container:getInventories()[1].itemCount end print("Item-Count:", sum) ``` -------------------------------- ### List All Installed Drives Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/drive.html This snippet iterates through the /dev directory to print the UUIDs of all connected drives. Ensure the filesystem is initialized before listing drives. ```lua -- Shorten name fs = filesystem -- Initialize /dev if fs.initFileSystem("/dev") == false then computer.panic("Cannot initialize /dev") end -- List all the drives for _, drive in pairs(fs.childs("/dev")) do print(drive) end ``` -------------------------------- ### Get Screen Source: https://docs.ficsit.app/ficsit-networks/latest/buildings/ComputerCase/GPUT1.html Returns the currently bound screen object. ```APIDOC ## Get Screen `getScreen` ### Description Returns the currently bound screen. ### Return Values #### Success Response - **screen** (Object(Object)) - The currently bound screen. ### Flags - RuntimeSync - RuntimeParallel ``` -------------------------------- ### Complete Button Control Script Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/ModularPanelAndEvents.html A complete script demonstrating how to get a panel reference, retrieve a button module, and set its color to bright red. ```lua local panel = component.proxy("...") local btn = panel:getModule(0,0,0) btn:setColor(1,0,0,5) ``` -------------------------------- ### Print Item Count Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/InteractingWithComponents.html Print the total item count to the console. This example combines retrieving the count and printing it in a single step. ```lua print("Item-Count:") ``` -------------------------------- ### get Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/structs/GPUT1Buffer.html Retrieves a single character and its foreground and background colors from the buffer at a specified position. ```APIDOC ## get ### Description Allows to get a single pixel from the buffer at the given position. ### Method MemberFunc ### Parameters #### Path Parameters - **X** `x` (Int) - Required - The x position of the character you want to get. - **Y** `y` (Int) - Required - The y position of the character you want to get. ### Return Values - **Char** `c` (String) - The character at the given position. - **Foreground Color** `foreground` (Struct) - The foreground color of the pixel at the given position. - **Background Color** `background` (Struct) - The background color of the pixel at the given position. ``` -------------------------------- ### Mount a Drive Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/drive.html This example demonstrates how to mount a drive to the root directory using its UUID. The filesystem must be initialized, and the drive's UUID must be known. ```lua -- Shorten name fs = filesystem -- Initialize /dev if fs.initFileSystem("/dev") == false then computer.panic("Cannot initialize /dev") end -- Let say UUID of the drive is 7A4324704A53821154104A87BE5688AC disk_uuid = "7A4324704A53821154104A87BE5688AC" -- Mount our drive to root fs.mount("/dev/"..disk_uuid, "/") ``` -------------------------------- ### Get Manufacturer Recipe Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/UsingReflection.html Retrieves the currently set recipe for a manufacturer component and prints its name. Ensure the manufacturer component is correctly proxied. ```lua local manufacturer = component.proxy(...) local recipe = manufacturer:getRecipe() ``` -------------------------------- ### Get Component Reference by GUID Source: https://docs.ficsit.app/ficsit-networks/latest/BasicConcept.html Use `component.proxy` with a component's GUID to get a reference to it. This is useful when you know the unique identifier of the component. ```lua constructor = component.proxy('0123456789…​') ``` -------------------------------- ### Get Wheelset Offset Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Returns the offset of the wheelset with the given index from the start of the vehicle. ```APIDOC ## Get Wheelset Offset `getWheelsetOffset` ### Description Returns the offset of the wheelset with the given index from the start of the vehicle. ### Method Not applicable (Function) ### Parameters #### Path Parameters - **Wheelset** (Int) - Required - The index of the wheelset you want to get the offset of. ### Return Values - **Offset** (Float) - The offset of the wheelset. ``` -------------------------------- ### _filesystem.initFileSystem Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Attempts to mount the system DevDevice to a specified location. ```APIDOC ## _filesystem.initFileSystem ### Description Trys to mount the system DevDevice to the given location. The DevDevice is a special Device holding DeviceNodes for all filesystems added to the system. It is unmountable as well as getting mounted a second time. ### Method _filesystem.initFileSystem ### Parameters #### Path Parameters - **path** (string) - Required - path to the mountpoint were the dev device should get mounted to ### Response #### Success Response (200) - **success** (boolean) - returns if it was able to mount the DevDevice ``` -------------------------------- ### _filesystem.makeFileSystem Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Creates a new filesystem of a specified type and name. ```APIDOC ## _filesystem.makeFileSystem ### Description Trys to create a new file system of the given type with the given name. The created filesystem will be added to the system DevDevice. Possible Types: * `tmpfs` A temporary filesystem only existing at runtime in the memory of your computer. All data will be lost when the system stops. ### Method _filesystem.makeFileSystem ### Parameters #### Path Parameters - **type** (string) - Required - the type of the new filesystem - **name** (string) - Required - the name of the new filesystem you want to create ### Response #### Success Response (200) - **success** (boolean) - returns true if it was able to create the new filesystem ``` -------------------------------- ### Creating and Using an Event Queue Source: https://docs.ficsit.app/ficsit-networks/latest/lua/Events.html Demonstrates the creation of an event queue with a filter and the use of the `pull` function. Ensure to use an appropriate filter for performance. ```lua function queue:pull(timeout) local _, e = future.first(self:waitFor{}, future.sleep(timeout)):await() if e then return table.unpack(e) end end ``` -------------------------------- ### Get Screen Drivers Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/PCIDevices.html Retrieves all installed screen drivers. This can be used as a replacement for the `getScreens` function from older mod versions. ```lua local Screens = computer.getPCIDevices(classes.FINComputerScreen) ``` -------------------------------- ### Get GPU T1 Devices Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/PCIDevices.html Retrieves all installed GPU T1 devices. This can be used as a replacement for the `getGPUs` function from older mod versions. ```lua local GPUs = computer.getPCIDevices(classes.FIN_GPU_T1) ``` -------------------------------- ### Constructing Structs using structs Library Source: https://docs.ficsit.app/ficsit-networks/latest/lua/index.html Illustrates how to create struct instances, such as Vector, using the 'structs' library. It shows both positional and named argument construction, as well as struct arithmetic. ```lua local vec1 = structs.Vector(0,1,2) local vec2 = structs.Vector{z = 5, x = 3, y = 4} local vec3 = vec1 + vec2 ``` -------------------------------- ### Computer A: Listen and Respond to Network Messages Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/InterComputerCommunication.html This script sets up a network card listener on Computer A, opens a specific port, and handles incoming messages. It responds to 'ping' with 'pong' and calls a local function 'foo' for 'foo' messages. ```lua local net = computer.getPCIDevices(classes.NetworkCard)[1] event.ignoreAll() event.listen(net) net:open(42) function foo(p1, p2, p3) print(p1, p2, p3) end while true do local data = {event.pull()} e, s, sender, port, data = (function(e,s,sender,port,...) return e, s, sender, port, {...} end)(table.unpack(data)) if e == "NetworkMessage" then if data[1] == "ping" then net:send(sender, port, "pong") elseif data[1] == "foo" then foo(table.unpack(data)) end end end ``` -------------------------------- ### Get Color Source: https://docs.ficsit.app/ficsit-networks/latest/buildings/IndicatorPole.html Allows to get the color and light intensity of the indicator lamp. This function is synchronized across runtime. ```APIDOC ## Get Color `getColor` ### Description Allows to get the color and light intensity of the indicator lamp. ### Return Values #### Return Values - **Red** `r` (Float _out_) - The red part of the color in which the light glows. (0.0 - 1.0) - **Green** `g` (Float _out_) - The green part of the color in which the light glows. (0.0 - 1.0) - **Blue** `b` (Float _out_) - The blue part of the color in which the light glows. (0.0 - 1.0) - **Emissive** `e` (Float _out_) - The light intensity of the pole. (0.0 - 5.0) ``` -------------------------------- ### Get Top Pole Source: https://docs.ficsit.app/ficsit-networks/latest/buildings/IndicatorPole.html Allows to get the pole placed on top of this pole. This function is synchronized across runtime. ```APIDOC ## Get Top Pole `getTopPole` ### Description Allows to get the pole placed on top of this pole. ### Return Values #### Return Values - **Top Pole** `topPole` (Object(IndicatorPole) _out_) - The pole placed on top of this pole. ``` -------------------------------- ### Metadata Function for 'getModule' Source: https://docs.ficsit.app/ficsit-networks/latest/ModIntegration.html This example shows the metadata function `netFuncMeta_getModule` for the `getModule` function. It defines the internal name, display name, description, and runtime for the function and its parameters. ```blueprint Begin Object Class=/Script/BlueprintGraph.K2Node_FunctionEntry Name="K2Node_FunctionEntry_0" ExtraFlags=201457664 FunctionReference=(MemberName="netFuncMeta_getModule") bIsEditable=True NodeGuid=A641581045D76519FC327387C72EA80C CustomProperties Pin ( PinId=6827195842DAF34DB2CEE5B11AFAD57A, PinName="then", Direction="EGPD_Output", PinType=(PinCategory="exec",PinSubCategory="",PinSubCategoryObject=None,PinSubCategoryMemberReference=(),PinValueType=(),ContainerType=None,bIsReference=False,bIsConst=False,bIsWeakPointer=False), LinkedTo=(K2Node_FunctionResult_0 1CE754E041DF05FB817829A28746ADE6,), PersistentGuid=00000000000000000000000000000000, bHidden=False, bNotConnectable=False, bDefaultValueIsReadOnly=False, bDefaultValueIsIgnored=False, bAdvancedView=False, bOrphanedPin=False, ) End Object Begin Object Class=/Script/BlueprintGraph.K2Node_FunctionResult Name="K2Node_FunctionResult_0" FunctionReference=(MemberName="netFuncMeta_getModule") bIsEditable=True NodePosX=640 NodeGuid=081353D84DCD947055E61EAA08C78451 CustomProperties Pin ( PinId=1CE754E041DF05FB817829A28746ADE6, PinName="execute", PinType=(PinCategory="exec",PinSubCategory="",PinSubCategoryObject=None,PinSubCategoryMemberReference=(),PinValueType=(),ContainerType=None,bIsReference=False,bIsConst=False,bIsWeakPointer=False), LinkedTo=(K2Node_FunctionEntry_0 ``` -------------------------------- ### Get Component Reference by UUID Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/InteractingWithComponents.html Use `component.proxy` to get a Lua reference to a component using its unique identifier (UUID). Replace '123' with the actual UUID of the component. ```lua local container = component.proxy("123") ``` -------------------------------- ### Get and Print Current Constructor Recipe Source: https://docs.ficsit.app/ficsit-networks/latest/BasicConcept.html This script finds a Constructor by its nickname, retrieves its current recipe using `getRecipe`, and prints the recipe name to the console. This demonstrates a complete workflow for interacting with a component. ```lua constructor = component.proxy(component.findComponent("WireFactory Constructor1")[1]) currentRecipe = constructor:getRecipe() print(currentRecipe) ``` -------------------------------- ### _computer.promote Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/ThreadedRuntimeModule.html Allows switching to a higher tick runtime state for faster code execution, especially for functions that can run asynchronously. ```APIDOC ## _computer.promote ### Description This function is mainly used to allow switching to a higher tick runtime state. Usually, you use this when you want to make your code run faster when using functions that can run in an asynchronous environment. ### Method `_computer.promote()` ### Endpoint N/A (Lua API) ### Parameters None ### Response None ``` -------------------------------- ### GPUT1Buffer.getSize Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Allows to get the dimensions of the buffer. ```APIDOC ## GPUT1Buffer.getSize ### Description Allows to get the dimensions of the buffer. ### Method N/A (Function within a structure) ### Parameters #### Out Parameters - **Width** (Float) - The width of this buffer - **Height** (Float) - The height of this buffer ### Return Values - **Width** (Float) - The width of this buffer - **Height** (Float) - The height of this buffer ``` -------------------------------- ### Get Opposite Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the opposite connection on the same track. ```APIDOC ## Get Opposite `getOpposite` ### Description Returns the opposite connection of the track this connection is part of. ### Method Not applicable (function call) ### Return Values #### Success Response - **Opposite** (Trace(RailroadTrackConnection)) - The opposite connection of the track this connection is part of. ``` -------------------------------- ### microcontroller.open Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/MicrocontrollerModule.html Opens a connection to the microcontroller. Accepts an integer and a variable number of arguments. ```APIDOC ## microcontroller.open ### Description Opens a connection to the microcontroller. ### Method Not specified (likely a function call within a Lua environment). ### Parameters - **integer** (integer) - Required - An integer argument, possibly an identifier or configuration setting. - **...** (any) - Variable arguments - Additional arguments may be required for establishing the connection. ``` -------------------------------- ### Get Station Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the station to which a connection belongs. ```APIDOC ## Get Station `getStation` ### Description Returns the station of which this connection is part of. ### Method Not applicable (function call) ### Return Values #### Success Response - **Station** (Trace(RailroadStation)) - The station of which this connection is part of. ``` -------------------------------- ### Initialize Sum Table Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/StructsAndClassInstances.html Initialize an empty table to store the sum of item counts, with item types as keys. ```lua local sum = {} ``` -------------------------------- ### Get Track Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the track to which a connection belongs. ```APIDOC ## Get Track `getTrack` ### Description Returns the track of which this connection is part of. ### Method Not applicable (function call) ### Return Values #### Success Response - **Track** (Trace(RailroadTrack)) - The track of which this connection is part of. ``` -------------------------------- ### Lua Event Filter Construction and Matching Example Source: https://docs.ficsit.app/ficsit-networks/latest/lua/Events.html Demonstrates how to construct EventFilters using various criteria (sender, event name, values) and combine them using logical operators (AND, OR, NOT). It also shows how to use these filters within a loop to process incoming events. ```lua local f1 = event.filter{sender=someSender, event="SomeEvent", values={someParameterName="someExpectedValue"}} local f2 = event.fitler{sender=someOtherSender} local f3 = f1 * f2 -- an AND link (both filters have to match) local f4 = f1 + f2 -- an OR link (one of the filters has to match) local f5 = -f1 -- an negation link (the filter is not allowed to match) local f5 = f3 + f4 * f5 -- you can essentially express complex conditions this way while true do local e = {event.pull()} if f1:matches(table.unpack(e)) then print("The event matches f1") end if f5:matches(table.unpack(e)) then print("The event matches the complex filter f5") end end ``` -------------------------------- ### switchPosition Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/RailroadSwitchControl.html Gets the current position of the railroad switch. ```APIDOC ## switchPosition ### Description Returns the current switch position of this switch. ### Method Not applicable (this is an SDK method). ### Endpoint Not applicable (this is an SDK method). ### Parameters None ### Response #### Success Response - **position** (Int) - The current switch position of this switch. ``` -------------------------------- ### _filesystem.createDir Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/FileSystemModule.html Creates a directory at the specified path, with an option for recursive creation. ```APIDOC ## _filesystem.createDir ### Description Creates the folder path. If recursive is false, it only creates the last folder in the path. If true, it creates all necessary parent folders. ### Parameters #### Path Parameters - **Path** (string) - The folder path the function should create. - **Recursive** (boolean) - If false, creates only the last folder of the path. If true, creates all folders in the path. ### Return Values #### Success Response - **Success** (boolean) - Returns true if the directory was successfully created. ``` -------------------------------- ### Get Next Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the next connection in the direction of the track. ```APIDOC ## Get Next `getNext` ### Description Returns the next connection in the direction of the track. ### Method Not applicable (function call) ### Return Values #### Success Response - **Next** (Trace(RailroadTrackConnection)) - The next connection in the direction of the track. ``` -------------------------------- ### _ReflectionFunction.quickRef Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/ReflectionSystemBaseModule.html Provides a string containing the signature and description of the function for quick informational access within code. ```APIDOC ## _ReflectionFunction.quickRef ### Description A string containing the signature and description of the function for a quick way to get info on the function within code. ### Method Call ### Parameters None ### Response #### Success Response - **string** - The signature and description of the function. ### Response Example ```json { "example": "function signature and description" } ``` ``` -------------------------------- ### Get Trailing Signal Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the signal that a connection is trailing from. ```APIDOC ## Get Trailing Signal `getTrailingSignal` ### Description Returns the signal this connection is trailing from. ### Method Not applicable (function call) ### Return Values #### Success Response - **Signal** (Trace(RailroadSignal)) - The signal this connection is trailing. ``` -------------------------------- ### Adding and Running Tasks with Future.loop() Source: https://docs.ficsit.app/ficsit-networks/latest/lua/Futures.html Shows how to add new tasks to the system using `future.addTask` and then start an infinite loop to process them with `future.loop()`. Tasks can be defined inline or by referencing existing functions with arguments. ```lua future.addTask(function() local i = 0 while true do print("i", i) i = i + 1 sleep(3) end end) function meep(prefix, timeout) local i = 0 while true do print(prefix, i) i = i + 1 sleep(timeout) end end future.addTask(meep, "j", 0.333) future.addTask(meep, "k", 30) future.loop() ``` -------------------------------- ### Infinite Task Loop Example Source: https://docs.ficsit.app/ficsit-networks/latest/lua/Futures.html Demonstrates an infinite loop that continuously runs futures in the task system using a round-robin approach. This is a common pattern for maintaining background processes. ```lua while true do future.run() coroutine.yield() end ``` -------------------------------- ### RailroadVehicle.GetTrackPos Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Gets the current position of the railroad vehicle on the track. ```APIDOC ## RailroadVehicle.GetTrackPos ### Description Returns the track pos at which this vehicle is. ### Function Signature `GetTrackPos() -> (Track, Offset, Forward)` ### Return Values - **track** (Trace(RailroadTrack)) - The track the track pos points to. - **offset** (Float) - The offset of the track pos. - **forward** (Float) - The forward direction of the track pos. 1 = with the track direction, -1 = against the track direction. ``` -------------------------------- ### VehicleScanner.getColor Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Allows to get the color and light intensity of the scanner. ```APIDOC ## VehicleScanner.getColor ### Description Allows to get the color and light intensity of the scanner. ### Method Not Applicable (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Return Values - **Red** (Float _out_) - The red part of the color in which the scanner glows. (0.0 - 1.0) - **Green** (Float _out_) - The green part of the color in which the scanner glows. (0.0 - 1.0) - **Blue** (Float _out_) - The blue part of the color in which the scanner glows. (0.0 - 1.0) - **Emissive** (Float _out_) - The light intensity of the scanner. (0.0 - 5.0) ### Request Example None ### Response #### Success Response None #### Response Example None ``` -------------------------------- ### Get Factory Connector and Listen to Events Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/UsingReflection.html Retrieves the first factory connector from a manufacturer and registers a listener for events on that connector. Assumes the connector is the desired output. ```lua local connector = manufacturer:getFactoryConnectors()[1] event.listen(connector) ``` -------------------------------- ### Paint Program Source: https://docs.ficsit.app/ficsit-networks/latest/lua/examples/paint.html This Lua script implements a basic paint program. It initializes a GPU and Screen, draws a color palette, and handles mouse events for drawing and color selection. Ensure you have a Lua CPU, Screen Driver, and GPU T1 available. ```lua -- get first T1 GPU avialable from PCI-Interface local gpu = computer.getPCIDevices(classes.GPUT1)[1] if not gpu then error("No GPU T1 found!") end -- get first Screen-Driver available from PCI-Interface local screen = computer.getPCIDevices(classes.FINComputerScreen)[1] -- if no screen found, try to find large screen from component network if not screen then local comp = component.findComponent(classes.Screen)[1] if not comp then error("No Screen found!") end screen = component.proxy(comp) end -- setup gpu event.listen(gpu) gpu:bindScreen(screen) w, h = gpu:getSize() -- clear background gpu:setBackground(0,0,0,0) gpu:fill(0, 0, w, h, " ", " ") -- setup color palette colors = {{0,0,0,0},{0,0,0,0},{1,0,0,1},{1,0,0,1},{0,1,0,1},{0,1,0,1},{0,0,1,1},{0,0,1,1},{1,1,1,1},{1,1,1,1}} -- draw color palette for i, color in ipairs(colors) do gpu:setBackground(color[1], color[2], color[3], color[4]) gpu:setText(i - 1, h - 1, " ") end gpu:setBackground(1,1,1,1) -- draw loop isDown = false while true do e, s, x, y = event.pull() if e == "OnMouseDown" then isDown = true -- is press on color palette, select color if y == h - 1 and x < #colors then color = colors[x + 1] gpu:setBackground(color[1], color[2], color[3], color[4]) end elseif e == "OnMouseUp" then isDown = false elseif e == "OnMouseMove" and not (y == h - 1 and x < #colors) and isDown then gpu:setText(x, y, " ") end gpu:flush() end ``` -------------------------------- ### IndicatorPole.getTopPole Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Allows to get the pole placed on top of this pole. ```APIDOC ## getTopPole IndicatorPole ### Description Allows to get the pole placed on top of this pole. ### Method (Not specified, likely a function call in an SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response - **topPole** (Object(IndicatorPole)) - The pole placed on top of this pole. #### Response Example ```json { "topPole": { ... } } ``` ``` -------------------------------- ### getCoupled Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/RailroadVehicle.html Allows to get the coupled vehicle at the given coupler. ```APIDOC ## Function: getCoupled ### Description Allows to get the coupled vehicle at the given coupler. ### Parameters #### Path Parameters - **coupler** (Int) - Required - The Coupler you want to get the car from. 0 = Front, 1 = Back ### Return Values #### Success Response - **coupled** (Trace) - The coupled car of the given coupler is coupled to another car. ``` -------------------------------- ### Full Example: Manufacturer Item Transfer Listener Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/UsingReflection.html A complete Lua script that proxies a manufacturer component, prints its recipe name, listens for item transfers on the first factory connector, and logs transfer events. ```lua local manufacturer = component.proxy(...) local recipe = manufacturer:getRecipe() print(recipe.name) local connector = manufacturer:getFactoryConnectors()[1] event.listen(connector) while true do e, s, i = event.pull() if e == "ItemTransfer" then print("Transfer!", i) end end ``` -------------------------------- ### _filesystem.open Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/FileSystemModule.html Opens a file stream for a given path and mode, returning a File table. Handles different read/write modes and file creation. ```APIDOC ## _filesystem.open ### Description Opens a file stream and returns it as a File table. Supports various modes for reading and writing. ### Parameters #### Path Parameters - **path** (string) - The path to the file to open. - **mode** (string) - The mode for the file stream (e.g., 'r', 'w', 'a', '+r', '+a'). ### Return Values #### Success Response - **file** (File) - The File table for the stream. Returns nil if the file cannot be opened in read-only mode. ``` -------------------------------- ### getWheelsetOffset Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/RailroadVehicleMovement.html Retrieves the offset of a specified wheelset from the start of the vehicle. ```APIDOC ## getWheelsetOffset ### Description Returns the offset of the wheelset with the given index from the start of the vehicle. ### Method Not applicable (SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **wheelset** (Int) - Required - The index of the wheelset you want to get the offset of. ### Response #### Success Response - **offset** (Float) - The offset of the wheelset. ### Response Example ```json { "offset": 2.5 } ``` ``` -------------------------------- ### GPUT1Buffer.get Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Allows to get a single pixel from the buffer at the given position. ```APIDOC ## GPUT1Buffer.get ### Description Allows to get a single pixel from the buffer at the given position. ### Method N/A (Function within a structure) ### Parameters #### Path Parameters - **X** (Int) - The x position of the character you want to get - **Y** (Int) - The y position of the character you want to get #### Out Parameters - **Char** (String) - The character at the given position - **Foreground Color** (Struct(Color)) - The foreground color of the pixel at the given position - **Background Color** (Struct(Color)) - The background color of the pixel at the given position ### Return Values - **Char** (String) - The character at the given position - **Foreground Color** (Struct(Color)) - The foreground color of the pixel at the given position - **Background Color** (Struct(Color)) - The background color of the pixel at the given position ``` -------------------------------- ### Get Wheelset Rotation Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Returns the current rotation of the given wheelset. ```APIDOC ## Get Wheelset Rotation `getWheelsetRotation` ### Description Returns the current rotation of the given wheelset. ### Method Not applicable (Function) ### Parameters #### Path Parameters - **Wheelset** (Int) - Required - The index of the wheelset you want to get the rotation of. ### Return Values - **X** (Float) - The wheelset’s rotation X component. - **Y** (Float) - The wheelset’s rotation Y component. - **Z** (Float) - The wheelset’s rotation Z component. ``` -------------------------------- ### _computer.media Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Provides access to the Media Subsystem. ```APIDOC ## _computer.media ### Description Field containing a reference to the Media Subsystem. ### Method _computer.media ``` -------------------------------- ### Get Switch Position Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the current position of a track switch. ```APIDOC ## Get Switch Position `getSwitchPosition` ### Description Returns the current switch position. ### Method Not applicable (function call) ### Return Values #### Success Response - **Index** (Int) - The index of the connection connection the switch currently points to. ``` -------------------------------- ### _filesystem.loadFile Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/FileSystemModule.html Loads a file as a Lua function from the specified path. ```APIDOC ## _filesystem.loadFile ### Description Loads the file referred to by the given path as a Lua function and returns it. This function fails if the path does not exist or does not refer to a file. ### Parameters #### Path Parameters - **Path** (string) - The path to the filesystem object to load. ### Return Values #### Success Response - **Code** (fun(): …​) - A function that runs the loaded code. ``` -------------------------------- ### Get Facing Signal Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the signal that a connection is facing towards. ```APIDOC ## Get Facing Signal `getFacingSignal` ### Description Returns the signal this connection is facing to. ### Method Not applicable (function call) ### Return Values #### Success Response - **Signal** (Trace(RailroadSignal)) - The signal this connection is facing. ``` -------------------------------- ### Assigning and Filtering Component Nicknames Source: https://docs.ficsit.app/ficsit-networks/latest/BasicConcept.html Components can be assigned nicknames for easier grouping and filtering. This example shows how to assign multiple nicknames and how different filters match these nicknames. ```lua nick1 = "Test Power" -- nick1 with names "Test" and "Power" nick2 = "Power" -- nick2 with name "Power" filter1 = "Power" -- nick filter maches nick1 and nick2 filter2 = "Test" -- nick filter maches only nick1 filter3 = "Test Power" -- nick filter maches only nick1 filter4 = "Power Nice" -- nick filter maches noone filter5 = "" -- nick filter maches every component (also components with no nick) ``` -------------------------------- ### Get Switch Control Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the switch control associated with a connection. ```APIDOC ## Get Switch Control `getSwitchControl` ### Description Returns the switch control of this connection. ### Method Not applicable (function call) ### Return Values #### Success Response - **Switch** (Trace(RailroadSwitchControl)) - The switch control of this connection. ``` -------------------------------- ### Get Storage Inventory Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the inventory containing the storage for the vehicle. ```APIDOC ## Get Storage Inventory `getStorageInv` ### Description Returns the inventory that contains the storage of the vehicle. ### Function Signature `getStorageInv()` ### Return Values - **Inventory** (Trace(Inventory)) - The storage inventory of the vehicle. ``` -------------------------------- ### Get Fuel Inventory Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the inventory containing the fuel for the vehicle. ```APIDOC ## Get Fuel Inventory `getFuelInv` ### Description Returns the inventory that contains the fuel of the vehicle. ### Function Signature `getFuelInv()` ### Return Values - **Inventory** (Trace(Inventory)) - The fuel inventory of the vehicle. ``` -------------------------------- ### Get Stops Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves a list of all stops currently in the time table. ```APIDOC ## Get Stops `getStops` ### Description Returns a list of all the stops this time table has. ### Return Values - **Stops** (Array(Struct(TimeTableStop)) _out_) - A list of time table stops this time table has. ``` -------------------------------- ### Get Targets Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves all target point structs currently in the list. ```APIDOC ## Get Targets `getTargets` ### Description Returns a list of target point structs of all the targets in the target point list. ### Method Not applicable (function call) ### Parameters #### Path Parameters - **targets** (Array(Struct(TargetPoint))) - Output - A list of target point structs containing all the targets of the target point list. ### Return Values - **targets** (Array(Struct(TargetPoint))) - A list of target point structs containing all the targets of the target point list. ``` -------------------------------- ### Find Components by Nick Query Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/AdvancedNetworking.html Use `component.findComponent` with space-separated nick queries to find matching component IDs. ```lua local comps1, comps2 = component.findComponent("test north", "okay") ``` -------------------------------- ### IndicatorPole.getColor Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Allows to get the color and light intensity of the indicator lamp. ```APIDOC ## getColor IndicatorPole ### Description Allows to get the color and light intensity of the indicator lamp. ### Method (Not specified, likely a function call in an SDK) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json {} ``` ### Response #### Success Response - **r** (Float out) - The red part of the color in which the light glows. (0.0 - 1.0) - **g** (Float out) - The green part of the color in which the light glows. (0.0 - 1.0) - **b** (Float out) - The blue part of the color in which the light glows. (0.0 - 1.0) - **e** (Float out) - The light intensity of the pole. (0.0 - 5.0) #### Response Example ```json { "r": 1.0, "g": 0.5, "b": 0.0, "e": 2.0 } ``` ``` -------------------------------- ### _filesystem.doFile Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/FileSystemModule.html Executes Lua code contained within a file at the specified path. ```APIDOC ## _filesystem.doFile ### Description Executes Lua code in the file referred to by the given path. This function fails if the path does not exist or does not refer to a file. It returns the result of the executed function or whatever it yielded. ### Parameters #### Path Parameters - **Path** (string) - The path to the filesystem object to execute. ### Return Values #### Success Response - **Results** (any) - The result of the execute function or what ever it yielded. ``` -------------------------------- ### Get Text Elements Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/structs/PrefabSignData.html Retrieves all text elements and their corresponding values. ```APIDOC ## getTextElements ### Description Returns all text elements and their values. ### Method `getTextElements() -> (Array, Array)` ### Return Values #### Success Response - **textElements** (Array) - The element names for all text elements. - **textElementValues** (Array) - The values for all text elements. ``` -------------------------------- ### Calling Functions Explicitly Source: https://docs.ficsit.app/ficsit-networks/latest/lua/BasicTypes.html Shows how to call a function by explicitly passing the instance as the first argument. This method allows for potential optimizations as the function lookup is done once. ```lua local constructor = ... constructor.getRecipe(constructor) -- calling the function with first parameter beeing the instance explicitly -- allows for optimizations like this because other wise the system would try to find the function everytime and that takes valuable time local func = constructor.getRecipe for i=0,100,1 do func(constructor) -- only function call, without the "search" of the function end ``` -------------------------------- ### Get Icon Elements Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/structs/PrefabSignData.html Retrieves all icon elements and their corresponding values. ```APIDOC ## getIconElements ### Description Returns all icon elements and their values. ### Method `getIconElements() -> (Array, Array)` ### Return Values #### Success Response - **iconElements** (Array) - The element names for all icon elements. - **iconElementValues** (Array) - The values for all icon elements. ``` -------------------------------- ### getOutputInv Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/Manufacturer.html Retrieves the output inventory of the manufacturer. ```APIDOC ## getOutputInv ### Description Returns the output inventory of this manufacturer. ### Method MemberFunc ### Parameters None ### Return Values - **inventory** (Trace) - The output inventory of this manufacturer. ``` -------------------------------- ### LightsControlPanel Class Methods Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Provides methods to configure and control lights connected to a control panel. ```APIDOC ## LightsControlPanel Class Methods ### isLightEnabled Gets or sets whether the lights connected to the panel are enabled. #### Property - **isLightEnabled** (bool) - True if the lights should be enabled. ### isTimeOfDayAware Gets or sets whether the lights should adjust based on the time of day. #### Property - **isTimeOfDayAware** (bool) - True if the lights should automatically turn on and off depending on the time of the day. ### intensity Gets or sets the intensity of the lights. #### Property - **intensity** (float) - The intensity of the lights. ### colorSlot Gets or sets the color slot used by the lights. #### Property - **colorSlot** (int) - The color slot the lights should use. ### setColorFromSlot Allows updating the light color referenced by a specific slot. #### Parameters - **slot** (int) - Required - The slot to update the referencing color for. - **color** (Struct(Color)) - Required - The color this slot should now reference. #### Function Signature `setColorFromSlot(int slot, Struct(Color) color)` ``` -------------------------------- ### Get Size Source: https://docs.ficsit.app/ficsit-networks/latest/buildings/ComputerCase/GPUT1.html Returns the current size of the text-grid and its associated buffer. ```APIDOC ## Get Size `getSize` ### Description Returns the size of the text-grid (and buffer). ### Return Values #### Success Response - **w** (Int) - The width of the text-gird. - **h** (Int) - The height of the text-grid. ### Flags - RuntimeSync - RuntimeParallel ``` -------------------------------- ### Get Modular Control Panel Reference Source: https://docs.ficsit.app/ficsit-networks/latest/lua/guide/ModularPanelAndEvents.html Obtain a reference to the modular control panel using its component address. Replace '...' with the actual address. ```lua local panel = component.proxy("...") ``` -------------------------------- ### _computer.millis Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/KernelModule.html Returns the number of milliseconds passed since the system started. ```APIDOC ## _computer.millis ### Description Returns the amount of milliseconds passed since the system started. ### Method _computer.millis ### Response #### Success Response (200) - **millis** (integer) - The amount of real milliseconds since the ingame-computer started ``` -------------------------------- ### _event.listen Source: https://docs.ficsit.app/ficsit-networks/latest/lua/api/EventModule.html Adds the running lua context to the listen queue of the given components, enabling it to receive signals from specified objects. ```APIDOC ## _event.listen ### Description Adds the running lua context to the listen queue of the given components. ### Method N/A (Lua function) ### Parameters #### Path Parameters - **Objects** (Object[]) - Required - A list of objects the computer should start listening to ``` -------------------------------- ### bindScreen Source: https://docs.ficsit.app/ficsit-networks/latest/reflection/classes/FINComputerGPU.html Binds this GPU to a new screen, automatically unbinding any previously bound screen. Pass null to unbind the current screen. ```APIDOC ## bindScreen ### Description Binds this GPU to the given screen. Unbinds the already bound screen. ### Method MemberFunc ### Parameters #### Parameters - **newScreen** (Trace) - Required - The screen you want to bind this GPU to. Null if you want to unbind the screen. ``` -------------------------------- ### Get Vehicle Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Returns the vehicle that this movement component holds the movement information of. ```APIDOC ## Get Vehicle `getVehicle` ### Description Returns the vehicle this movement component holds the movement information of. ### Method Not applicable (Function) ### Parameters None ### Return Values - **vehicle** (Trace(RailroadVehicle)) - The vehicle this movement component holds the movement information of. ``` -------------------------------- ### Get Target List Source: https://docs.ficsit.app/ficsit-networks/latest/Reflection.html Retrieves the list of targets or path waypoints for the vehicle. ```APIDOC ## Get Target List `getTargetList` ### Description Returns the list of targets/path waypoints. ### Function Signature `getTargetList()` ### Return Values - **Target List** (Trace(TargetList) out) - The list of targets/path-waypoints. ```