XScript Manual · Chapter 2

title: "Language Basics — variables, functions, sequences, steps" chapter: 2 images:

  • xscript-variable.png
  • xscript-function.png

Language Basics

An XScript program is built from four building blocks.

ElementDescription
VariableGlobal/local state — counters, flags, positions
FunctionReusable logic unit
SequenceState-transition block executed cyclically by the main loop
StepA stage inside a sequence
Declaring variables in the Variable tab

Supported Types

TypeDescription
int · uintInteger
doubleFloating point
booltrue/false (or ON/OFF)
stringText. Interpolation with $"Hello {name}"
arrayDynamic array

Variables

Globals live in the Variable editor, locals inside a function body. Opening braces always go on the next line.

int count = 0;
bool initOk = false;
double targetPos = 100.0;
string jobName = "default";
 
// Access to module variables
MachineLoaded = false;
SS.UnitCount = 10;
SYS.DateString;

Constants

Constants are declared in DATA.Const or the Constant Editor and are read-only globally.

int n = MAX_NUM_UNIT;
string name = DEVICE_NAME;

Functions

Declared with the FUNCTION keyword. Opening brace on the next line.

FUNCTION CheckLoad()
{
    if (IO["LOAD_SENSOR"] == ON)
    {
        return true;
    }
    return false;
}
 
FUNCTION MoveToPos(double pos, bool wait)
{
    MOTOR["M_X"].SetSpeed("RUN");
    if (MOTOR["M_X"].MoveAbs(pos, wait) == false)
    {
        return false;
    }
    return true;
}
  • Return type is inferred; convention is to return bool for success/failure.
  • Call by named parameter is supported: MoveToPos(/*pos*/100.0, /*wait*/true).
Function tab

Sequences and Steps

A Sequence is the block the main loop cycles through; a Step is an internal state. Jump with goto "STEP_name".

////SEQUENCE,Seq
 
////STEP,STEP_Idle
UpdateData();
Sleep(100);
 
UnitData::UnitStatus[unitIndex] = "--";
 
if (unitIndex >= SS.UnitCount)
{
    Sleep(2000);
    return false;
}
 
if (unitIndex > 0)
{
    goto "STEP_Get";
}
 
////STEP,STEP_WaitOrder
Sleep(200);
 
if (IO[cnvSensorName].CheckContiOn(2000) == false)
{
    return false;
}
 
if (ProcessOrder() == false)
{
    return false;
}
 
////STEP,STEP_Get
// ... receive material
  • Each step runs like an independent function; return false ends the current cycle.
  • Module variables (e.g. unitIndex) persist between steps.

View Module

UI modules have three parts: Design (XAML), Variable (bindings), Functions (OnShow, OnHide, OnTimer, OnClickEvent, …).

FUNCTION OnShow(string sender, int tag, array params)
{
    UpdateOrderDisplay();
    ViewSetup::UpdateUnitList();
}
 
FUNCTION OnTimer(string sender, int tag, array params)
{
    UpdateOrderDisplay();
    count++;
}