Native Functions

Updated: 2025-11-21

Native functions allow operating directly on the contents of a variable, whether numeric, string, array, or object. Some functions modify the variable in place.

The format is always the same:

ASSIGN.<FUNCTION> targetVariable, parameter [,targetEntityNumber]
SAVEVALUE.<FUNCTION> targetVariable, parameter

If the variable does not exist, it is created.

It is very important to note that JSON objects and arrays can only be created using these two blocks and the INITIAL command. Any other COMMAND or BLOCK that requires object or array parameters must receive an already-created structure via the SNA V$(variable).

CALL fun, V$(structure)
CALL fun, P$(variable)
CALL fun, {name:"Antonio"} ; objects are not interpreted outside ASSIGN, SAVEVALUE or INITIAL
CALL fun, [1,2,V$(otherList)] ; objects are not interpreted outside ASSIGN, SAVEVALUE or INITIAL

Functions:

1. Numeric variables

  • .INC value – increments the current value, 1 by default. Modifies its contents
    ASSIGN.INC counter
    ASSIGN.INC counter,10
    ASSIGN.INC myObject.score
    

2. String variables

  • .TRIM – removes leading and trailing spaces Modifies its contents
    ASSIGN.TRIM myString
    
  • .LENGTH – returns the string length Stores the result in another variable
    ASSIGN.LENGTH myString, length
    
  • .JOIN – joins elements into a string Returns a new value
    ASSIGN.JOIN finalString, {DATA:["one","two","three"], SEP:" - "}
    ASSIGN.JOIN finalString, {DATA:V$myArray, SEP:" - "}
    

3. Array variables

  • .PUSH value – adds to the end
    .UNSHIFT value – adds to the beginning
    .EXTEND array – appends elements from another array
  • .SPLIT – splits a string into an array
  • .SLICE – takes a section of an array between START and END (END not included)

4. Object variables

  • .MERGE object – merges keys from another object
    .DELETE path – removes a property Modifies contents
  • .KEYS – returns a list of key names Stores the result in another variable

Access paths

The DSL allows assigning values to internal parts of objects or arrays using dot-separated paths.

Object paths do not auto-create intermediate levels. If a path does not exist, an error is raised and the simulation stops.

Array paths allow direct access to any index, even if empty.

SNA VD$

Some data can be accessed directly using the associated SNA for validation and inspection:

  • VD$(path) – raw unprocessed value.
  • VD$(path,LENGTH) – content length.
  • VD$(path,TYPEOF) – data type as text.
  • VD$(path,ISEMPTY) – returns "1" if empty, "0" otherwise.
  • VD$(path,EXIST) – checks if the full path exists.
  • VD$(path,HASKEY,key) – checks if an object has a given key.
  • VD$(path,INCLUDES,value) – checks if an array or string includes a value.

Example

POSITION {NAME:POS1,X:300,Y:100}

INITIAL posY,500
GRAPHIC {NAME:Text1,Type:TEXT,X:324,Y:X$posY - 0}
GRAPHIC {NAME:Text2,Type:TEXT,X:324,Y:X$posY - 20}
GRAPHIC {NAME:Text3,Type:TEXT,X:324,Y:X$posY - 40}
GRAPHIC {NAME:Text4,Type:TEXT,X:324,Y:X$posY - 60}
GRAPHIC {NAME:Text5,Type:TEXT,X:324,Y:X$posY - 80}
GRAPHIC {NAME:Text6,Type:TEXT,X:324,Y:X$posY - 100}
GRAPHIC {NAME:Text7,Type:TEXT,X:324,Y:X$posY - 120}
GRAPHIC {NAME:Text8,Type:TEXT,X:324,Y:X$posY - 140}
GRAPHIC {NAME:Text9,Type:TEXT,X:324,Y:X$posY - 160}
GRAPHIC {NAME:Text10,Type:TEXT,X:324,Y:X$posY - 180}
GRAPHIC {NAME:Text11,Type:TEXT,X:324,Y:X$posY - 200}
GRAPHIC {NAME:Text12,Type:TEXT,X:324,Y:X$posY - 220}
GRAPHIC {NAME:Text13,Type:TEXT,X:324,Y:X$posY - 240}
GRAPHIC {NAME:Text14,Type:TEXT,X:324,Y:X$posY - 260}

START 1

GENERATE 1,0,0,1 {NAME:GEN1,X:100,Y:100}

; Base variables
ASSIGN greeting, "Hello"
ASSIGN complement, "world"
ASSIGN originalMessage, "   Hello World GPSS+   "
ASSIGN names, ["Ana", "Luis", "Eva"]
ASSIGN otherNames, ["Sonia", "David"]
ASSIGN textWithSeparator, "one,two,three,four,five"

; Array methods
ASSIGN.PUSH names, "Ricardo" ; ["Ana", "Luis", "Eva", "Ricardo"]
ASSIGN.UNSHIFT names, "Laura" ; ["Laura", "Ana", "Luis", "Eva", "Ricardo"]
ASSIGN.EXTEND names, V$otherNames ; ["Laura", "Ana", "Luis", "Eva", "Ricardo", "Sonia", "David"]
ASSIGN.SLICE names, {START:1,END:6} ; ["Ana", "Luis", "Eva", "Ricardo", "Sonia"]

; String methods
ASSIGN.JOIN finalMessage, {DATA:["P$greeting", " ", "P$complement", "!"]} ; "Hello world!"
ASSIGN.JOIN namesText, {DATA:V$names,SEP:" - "} ; "Ana - Luis - Eva"
ASSIGN.SPLIT words, {DATA:V$textWithSeparator, SEP:","} ; ["one","two","three","four","five"]
ASSIGN.TRIM originalMessage ; "Hello World GPSS+"
ASSIGN.LENGTH originalMessage, messageLength ; 16

; Objects
ASSIGN data, {name:"John", age:25}
ASSIGN newData, {city:"Madrid", age:30}
ASSIGN.MERGE data, V$newData
ASSIGN.DELETE data, city

; Numeric
ASSIGN counter, 10
ASSIGN.INC counter,-5
ASSIGN.INC counter

; Keys
ASSIGN students, {ana:{age:20}, luis:{age:25}}
ASSIGN.KEYS students, studentKeys

; Access paths
ASSIGN myObject, {}
ASSIGN myObject.key1, 123
;ASSIGN myObject.key2.otherLevel, "error" -> error because it does not exist
ASSIGN myArray, []
ASSIGN myArray.2, 99
ASSIGN myArray.3, []
ASSIGN.PUSH myArray.3, 199

; Display results
MOVE {NAME:Text1, TEXT:"Final message: P$finalMessage"}
MOVE {NAME:Text2, TEXT:"Names (2): P$(names.2) LENGTH: VD$(names,LENGTH)"}
MOVE {NAME:Text3, TEXT:"Names text: P$namesText"}
MOVE {NAME:Text4, TEXT:"Words[1]: P$(words.1)"}
MOVE {NAME:Text5, TEXT:"Trimmed text: P$originalMessage"}
MOVE {NAME:Text6, TEXT:"Message length: P$messageLength"}
MOVE {NAME:Text7, TEXT:"data.age: P$(data.age)"}
MOVE {NAME:Text8, TEXT:"data.city: P$(data.city)"} ; should be empty
MOVE {NAME:Text9, TEXT:"Final counter: P$counter"}
MOVE {NAME:Text10, TEXT:"studentKeys[1]: P$(studentKeys.1)"}
MOVE {NAME:Text11, TEXT:"Type of names: VD$(names,TYPEOF)"}
MOVE {NAME:Text12, TEXT:"Students has luis?: VD$(students,HASKEY,luis)"}
MOVE {NAME:Text13, TEXT:"myObject.key1: P$(myObject.key1)"}
MOVE {NAME:Text14, TEXT:"myArray.3.0: P$(myArray.3.0)"}

ADVANCE 100,0 {TO:POS1}
ENDGENERATE 1