Learn FACTORY-IO-SCRIPTING with Real Code Examples
Updated Nov 27, 2025
Code Sample Descriptions
1
Factory I/O Toggle Sensor Output
void Update() {
bool sensor = IOLink.GetBool("Sensor1");
IOLink.SetBool("Actuator1", sensor);
}
Read a digital sensor and toggle an output actuator.
2
Factory I/O Timed Conveyor Start
float timer = 0;
bool running = false;
void Update() {
if (IOLink.GetBool("EntrySensor") && !running) {
running = true;
timer = 3f;
IOLink.SetBool("Conveyor", true);
}
if (running) {
timer -= Time.deltaTime;
if (timer <= 0) {
IOLink.SetBool("Conveyor", false);
running = false;
}
}
}
Start the conveyor for 3 seconds whenever a sensor triggers.
3
Factory I/O Counter for Produced Items
int count = 0;
void Update() {
if (IOLink.GetBool("OpticSensor")) {
count++;
Debug.Log("Items: " + count);
}
}
Count items detected by an optical sensor.
4
Factory I/O Sorting with Two Actuators
void Update() {
int color = IOLink.GetInt("ColorID");
if (color == 1) {
IOLink.SetBool("PusherLeft", true);
}
else if (color == 2) {
IOLink.SetBool("PusherRight", true);
}
else {
IOLink.SetBool("PusherLeft", false);
IOLink.SetBool("PusherRight", false);
}
}
Sort items left or right based on color sensor.
5
Factory I/O Emergency Stop Logic
void Update() {
if (IOLink.GetBool("EmergencyStop")) {
IOLink.SetBool("Motor1", false);
IOLink.SetBool("Motor2", false);
IOLink.SetBool("Conveyor", false);
}
}
Stop all outputs if an emergency switch is pressed.
6
Factory I/O Light Stack Indicator
void Update() {
bool idle = IOLink.GetBool("IdleState");
bool running = IOLink.GetBool("RunState");
bool fault = IOLink.GetBool("FaultState");
IOLink.SetBool("LightGreen", running);
IOLink.SetBool("LightYellow", idle);
IOLink.SetBool("LightRed", fault);
}
Control a stack light (red/yellow/green) based on machine states.
7
Factory I/O Palletizer Robot Cycle
void Update() {
if (IOLink.GetBool("BoxArrived")) {
IOLink.SetBool("RobotGrab", true);
IOLink.SetBool("RobotMoveToStack", true);
}
if (IOLink.GetBool("RobotAtStack")) {
IOLink.SetBool("RobotGrab", false);
IOLink.SetBool("RobotReturn", true);
}
}
Automate a simple pick-and-place robot cycle.
8
Factory I/O Variable Speed Conveyor
void Update() {
float speed = IOLink.GetFloat("SpeedDial");
IOLink.SetFloat("ConveyorSpeed", speed);
}
Control conveyor speed dynamically from an analog input.
9
Factory I/O Fault Reset Handling
int itemCount = 0;
void Update() {
if (IOLink.GetBool("ResetButton")) {
itemCount = 0;
IOLink.SetBool("Actuator1", false);
IOLink.SetBool("Actuator2", false);
}
}
Reset actuators and counters when a reset button is pressed.
10
Factory I/O Multi-Sensor Condition Check
void Update() {
bool s1 = IOLink.GetBool("Sensor1");
bool s2 = IOLink.GetBool("Sensor2");
bool s3 = IOLink.GetBool("Sensor3");
bool fault = s1 || s2 || s3;
IOLink.SetBool("Alarm", fault);
}
Trigger an alarm if any sensor in a group detects an issue.