MultiScript Language Syntax

MultiScript is Multi Commander's built-in scripting language that provides powerful automation capabilities through a simple yet comprehensive syntax. Understanding MultiScript syntax enables you to create sophisticated automation scripts, custom commands, and advanced file management workflows that extend Multi Commander's functionality beyond basic operations.

Comprehensive Scripting Language

MultiScript provides a complete programming environment with variables, functions, classes, control structures, and extensive built-in functions. The language is designed for ease of use while maintaining the power needed for complex automation tasks in file management and system administration scenarios.

Basic Language Syntax Rules

MultiScript follows specific syntax rules that ensure consistent and predictable script execution across all Multi Commander environments.

Fundamental Syntax Rules
Script Execution Model
  • Line-by-Line Processing: MultiScript is a line-by-line engine - every command must be on a single line
  • Statement Termination: Commands should end with semicolon (;) for future compatibility
  • Scope Declaration: New scope is declared with curly braces { } for conditions, loops, functions, and classes
  • Expression Evaluation: Left-to-right evaluation with parentheses taking precedence
Comment Syntax
  • Comment Lines: Lines starting with // or # are treated as comments
  • Inline Comments: Not supported - comments cannot be on the same line as valid code
  • Documentation: Use comments to document complex logic and script functionality
Expression Evaluation Important

Operator Precedence: MultiScript evaluates expressions left-to-right without operator precedence. Use parentheses to control evaluation order: 2 + 4 * 8 equals 48, but 2 + (4 * 8) equals 34.

Basic Syntax Example
// Calculate string length
@var $str = "Hello World";
@var $len = StrLen($str);
if( $len > 10 )
{
  $str = "Too long";
}
Reserved Keywords
if for while break
continue return function class
new @var @gvar

These words cannot be used for variable or function names.

Data Types and Variables

MultiScript supports five primary data types with automatic type conversion capabilities and flexible variable declaration options for various programming scenarios.

Supported Data Types
Data Type Description Examples
String Text data with escape sequence support "Hello World", 'File path', "Line1\nLine2"
Number Integer and floating-point values 42, 3.14, -100
Array Collection of multiple values {"item1", "item2"}, {1, 2, 3}
Object Class instances with properties and methods new MyClass, $obj.property
Handle References to system resources FilterCreate(), $filter
Type Conversion Features
  • Automatic Conversion: String-to-number and number-to-string conversions happen automatically
  • String Concatenation: Numbers can be concatenated directly to strings
  • Type Checking Functions: IsTypeString(), IsTypeNum(), IsTypeArray(), IsTypeHandle()
  • Manual Conversion: strtonum() and numtostr() for explicit type conversion
Variable Declaration
Variable Declaration Syntax
// Single variable
@var $v1;

// Multiple variables
@var $v1, $v2, $v3;

// With initialization
@var $v1 = 0;
@var $v2 = "Hello";
@var $v3 = MyFunc();

// Global scope variable
@gvar $globalVar;
Variable Rules
  • Naming: Must start with $, contain only a-z, A-Z, 0-9
  • Scope: Variables exist within their declaration scope
  • Shadowing: Local variables can shadow outer scope variables
  • Global Access: Use @gvar to declare in global scope
Arrays and Constants
Array Declaration
// Fixed size array
@var $arr[3];

// Initialized arrays
@var $strArr[] = {"A", "B", "C"};
@var $numArr[] = {1, 2, 3};

// Mixed type array
@var $mixed[] = {"text", 42, "more"};
String Constants and Escape Sequences
\nNewline
\rCarriage return
\tTab
\"Double quote
\\Backslash

Note: Use double quotes for escape sequences, single quotes for literal strings.

Operators and Expressions

MultiScript provides comprehensive operator support for arithmetic, comparison, assignment, and special operations including the unique path concatenation operator for file system operations.

Complete Operator Reference
Arithmetic Operators
OperatorDescriptionExample
+Addition / String concatenation5 + 3, "A" + "B"
-Subtraction10 - 3
*Multiplication4 * 5
/Division20 / 4
Assignment Operators
OperatorDescriptionExample
=Assignment$x = 5
+=Add and assign$x += 3
-=Subtract and assign$x -= 2
Comparison Operators
OperatorDescriptionExample
==Equal to$x == 5
>Greater than$x > 10
<Less than$x < 20
>=Greater or equal$x >= 5
<=Less or equal$x <= 15
Special Operators
OperatorDescriptionExample
!Logical negation!$condition
^Path concatenation$path ^ "file.txt"
[ ]Index operator$arr[0], $str[2]
Path Concatenation Operator

The ^ operator intelligently handles path separation: "C:\Path" ^ "file.txt" becomes "C:\Path\file.txt", automatically adding backslashes when needed while removing duplicates.

Expression Examples
// Arithmetic with parentheses
@var $result = 5 + (4 * 2); // = 13

// String concatenation
@var $msg = "Hello" + " " + "World";

// Path operations
@var $fullPath = $basePath ^ $fileName;

// Comparison
if( $value >= 10 && $value <= 20 )
{
  // Process value in range
}
Index Operator Usage
// Array indexing
@var $arr[] = {"A", "B", "C"};
@var $first = $arr[0];  // "A"
$arr[1] = "Modified";   // Change element

// String character access
@var $str = "Hello";
@var $firstChar = $str[0];  // "H"
$str[0] = "J";             // "Jello"

// Character manipulation
@var $str2 = "12345";
$str[1] = $str2[3];        // "H4llo"

Control Structures

MultiScript provides standard control structures for conditional execution and iteration, enabling complex program logic and automated processing workflows.

Conditional Statements
IF-ELSE Structure
if( $condition )
{
  // Execute if true
}
else if( $otherCondition )
{
  // Execute if first false, this true
}
else
{
  // Execute if all conditions false
}
Conditional Logic Rules
  • Boolean Evaluation: Values ? 1 are true, < 1 are false
  • Scope Variables: Variables declared inside IF scope are local
  • Variable Shadowing: Inner scope variables can shadow outer ones
  • Nested Conditions: IF statements can be nested to any depth
Loop Structures
FOR Loop
@var $n;
for( $n = 0; $n < 5; $n++ )
{
  if( $n == 2 )
  {
    continue; // Skip iteration
  }
  if( $n == 4 )
  {
    break;    // Exit loop
  }
}
WHILE Loop
@var $n = 10;
while( $n > 0 )
{
  $n--;
  // Process items
}

Note: Loop variable must be declared outside the FOR statement.

Loop Control and Flow
Loop Control Keywords
  • break: Exit the loop immediately
  • continue: Skip to next iteration
  • return: Exit function and optionally return value
FOR Loop Components
  • Init Expression: Executed once before loop starts
  • Condition: Evaluated before each iteration
  • Loop Expression: Executed after each iteration
WHILE Loop Features
  • Condition Check: Evaluated before each iteration
  • Variable Scope: Access to outer scope variables
  • Infinite Loops: Use break or return to exit

Functions and Classes

MultiScript supports user-defined functions and basic object-oriented programming through classes, enabling code reuse, modular design, and organized script architecture.

Function Definition
Function Syntax
function MyFunction( $param1, $param2 )
{
  @var $result = $param1 + $param2;
  $result = $result * 2;
  return $result;
}

// Function call
@var $value = MyFunction( 5, 10 );
Function Features
  • Declaration Order: Functions must be defined before they are called
  • Parameter Passing: All parameters passed by value (copied)
  • Return Values: Functions return 1 by default, use return for custom values
  • Local Scope: Function variables are local to the function
Class Definition
Class Syntax
class MyClass
{
  @var $property1 = 0;
  @var $property2 = "default";
  
  function MyMethod( $param )
  {
    $property1 = $param;
    return $property1 * 2;
  }
}

// Object creation and usage
@var $obj = new MyClass;
@var $result = $obj.MyMethod( 10 );
@var $value = $obj.property1;
Class Features
  • Object Creation: Use new keyword to create instances
  • Property Access: Use dot notation without $ prefix
  • Method Calls: Standard function call syntax with dot notation
  • Public Access: All properties and methods are public
Advanced Function and Class Concepts
Function Best Practices
  • Early Definition: Define all functions at the beginning of scripts
  • Meaningful Names: Use descriptive function names that indicate purpose
  • Return Values: Always use explicit return statements for clarity
  • Error Handling: Validate parameters and handle edge cases
  • Documentation: Use comments to document function purpose and parameters
Parameter Passing Example
function ModifyValue( $input )
{
  $input = $input * 2;  // Only modifies copy
  return $input;
}

@var $original = 10;
@var $modified = ModifyValue( $original );
// $original is still 10, $modified is 20
Class Usage Patterns
  • Object Lifetime: Objects exist until script completion
  • No Destructors: Cannot explicitly delete objects
  • Simple OOP: Basic object-oriented features without inheritance
  • State Management: Use objects to maintain related data and methods
  • Encapsulation: Group related functionality in logical units
Object Property Access
// INCORRECT - Don't use $ in property access
@var $value = $obj.$property;

// CORRECT - Use dot notation without $
@var $value = $obj.property;
$obj.property = "new value";

// Method calls
@var $result = $obj.CalculateValue( $param );
MultiScript Syntax Mastery

Master MultiScript by understanding line-by-line execution, using parentheses for expression control, and leveraging the powerful data types and operators. Remember that variables must start with $, functions must be defined before use, and the path concatenation operator ^ simplifies file system operations. Use proper scoping with @var for local and @gvar for global variables, and always validate expressions with parentheses when combining multiple operations for predictable results.

Related MultiScript Documentation

Continue learning MultiScript with: Core Functions, String Functions, Array Functions, File System Functions, Practical Examples, User Defined Commands, and MultiScript Debugger.