Variables are storage locations with a specific type. DWScript supports both modern inline declarations and traditional Pascal-style blocks.
You can specify the type explicitly using the name : Type syntax.
var x : Integer;
var name : String;
x := 10;
name := 'Alice'; You can combine declaration and assignment in a single statement.
var f : Float := 10;
var status : String := 'Initializing';
PrintLn(f); 10
Modern DWScript can infer the type of a variable from its initial assignment. This is the preferred style for local variables as it reduces redundancy.
var count := 42; // Inferred as Integer
var price := 19.99; // Inferred as Float
var message := 'Hello'; // Inferred as String
var active := True; // Inferred as Boolean In script mode, variables can be declared anywhere before their first use.
PrintLn('Step 1');
var x := 100;
PrintLn(x); Step 1 100
DWScript also supports the classic Pascal structure where variables are declared in a var block before the begin keyword of a procedure or function.
procedure ProcessData;
var
i : Integer;
s : String;
begin
i := 5;
s := 'Value: ';
PrintLn(s + IntToStr(i));
end;
ProcessData; Value: 5
If you need to use a reserved Pascal keyword (like type, begin, end, repeat, etc.) as an identifier for a variable, field, or function, you can prefix it with an ampersand &.
The compiler will treat the identifier as if the ampersand were not there, allowing you to interface with external systems (like JSON APIs) that use these names.
var &type := 'System';
var &repeat := True;
PrintLn(&type); System
Variable visibility and lifetime are determined by where they are declared:
procedure, function, or block (like a for loop) are only visible within that block. Their lifetime is tied to the procedure they are in.var x := 'Global';
procedure Test;
var x := 'Local'; // Shadows global x
begin
PrintLn(x);
end;
Test;
PrintLn(x); Local Global
Variables in DWScript are guaranteed to be initialized to their default values (0 for numbers, '' for strings, nil for objects/arrays, False for booleans). You do not need to manually initialize them to zero/nil.