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.
| Element | Description |
|---|---|
| Variable | Global/local state — counters, flags, positions |
| Function | Reusable logic unit |
| Sequence | State-transition block executed cyclically by the main loop |
| Step | A stage inside a sequence |
캡처 대기
public/manual/gui/xscript-variable.pngSupported Types
| Type | Description |
|---|---|
int · uint | Integer |
double | Floating point |
bool | true/false (or ON/OFF) |
string | Text. Interpolation with $"Hello {name}" |
array | Dynamic 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
boolfor success/failure. - Call by named parameter is supported:
MoveToPos(/*pos*/100.0, /*wait*/true).
캡처 대기
public/manual/gui/xscript-function.pngSequences 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 falseends 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++;
}