Welcome to DWScript. If you are familiar with Pascal or Delphi, you will feel right at home. If you are coming from JavaScript or PHP, you will appreciate the structure and clarity that Pascal brings.
Let's start with the classic example. In DWScript, a standalone script is simply a sequence of statements.
PrintLn('Hello World'); Hello World
When this script runs on the server, it outputs:
Scripts can contain:
PrintLn).Statements are separated by semicolons ;. Blocks of code are enclosed in begin and end keywords.
var x : Integer;
x := 10;
if x > 5 then begin
PrintLn('x is greater than 5');
end; x is greater than 5
Comments are ignored by the compiler and are used to document your code. DWScript supports standard Pascal comments as well as C-style block comments.
// Single line comment
{
Multi-line block comment
}
(*
Another style of multi-line comment
*)
/*
C-style block comment
*/ Identifiers are names you give to variables, constants, procedures, and other entities. They must start with a letter or underscore, followed by letters, numbers, or underscores.
You cannot use reserved keywords (like type, begin, if) directly as identifiers. However, you can use them by prefixing them with an ampersand &.
var &type := 'System'; // 'type' is a reserved word
PrintLn(&type); System
Directives are special instructions to the compiler that start with {$. They are used for conditional compilation, including files, and controlling compiler behavior.
{$IFDEF DEBUG}
// This code only compiles if DEBUG is defined
PrintLn('Debug Mode');
{$ENDIF}