Skip to main content

ObjectScript Quick Introduction

Here's the world's quickest introduction to ObjectScript commands, operators, and functions.

Commands
Set Assign a value to a variable, e.g. SET A = 1
Do Execute a method or subroutine, e.g. DO X(43)
If ... ElseIf ... Else Conditional execution (THEN is implicit).
For Loop using a counter, e.g. FOR X = 1 : 1 : 100 In FOR X = A : B : C, A is the starting value, B the increment, and C the ending value.
While & Do ... While Loop until a condition is true, e.g.WHILE A < 10 { SET B = B + 1 }.
Quit Exit from a method, subroutine or FOR loop
Operators
+ - * / The usual arithmetic operators: addition, subtraction, multiplication, division.
** Exponentiation.
\ Integer Division.
# Modulo.
= < > Logical Comparisons.
' Logical NOT (a single quote).
&& || Logical AND and OR.
_ String concatenation (an underscore).
? Pattern match. Very powerful, but too rich to explain here.
Functions
$Case Compare an expression with a set of cases and return the value associated with the first matching case. For instance, $CASE(X, 6:"Weekend",7:"Weekend",:"Weekday"), returns “Weekend” if X equals 6 or 7 and “Weekday” otherwise.
$Extract Return a portion of a string.
$Find Find characters within a string.
$FNumber Format a number, e.g. $FNUMBER(X, ",", 2) uses commas as the thousands separators and displays two decimal places.
$Get Fetch the value of a variable or return a default value if the variable is undefined, e.g. SET A = $GET(X, 3) —If X is undefined, A = 3, otherwise A = X.
$Horolog Get the current date and time.
$Length Determine the length of a string.
$List One of a set of functions for manipulating lists.
$Piece Extact substrings from a string using a delimiter character.
$Translate Perform character translations.
$Zdate Formats a date value.
$Ztime Formats a time value.

To learn more about ObjectScript, consult the ObjectScript Language Reference.

FeedbackOpens in a new tab