Objects and arrays in ASSIGN and SAVEVALUE

Updated: 2026-01-04

As far as the language is concerned, the evolution from classic GPSS to GPSS-Plus has two major turning points:

  • The introduction of STACKS, which enable loops, nested calls, and complex control structures.
  • The expansion of the SAVEVALUE and ASSIGN variable system, which now stores not only numbers but also strings, arrays, and objects, and allows functions to be executed on them.

This second advance makes older elements like MATRIX obsolete and allows GPSS-Plus to include native functions found in any modern language such as push, concat, merge, or split, all within the simulator’s own logic and without resorting to external programming. What used to be solved with rigid tools can now be done in an expressive, structured, and maintainable way. GPSS-Plus stops being a card-based language with numbers and becomes a full-purpose DSL, oriented to event flows and structured data manipulation.

We already know GPSS-Plus lets you declare variables with two scope levels:

  • ASSIGN: entity-local variable.
  • SAVEVALUE: global variable, shared among entities.

Their behavior is identical except for visibility. In both cases, variables can hold different data types:

  • Numbers: written as usual: 123.4
  • Strings: always in double quotes: "Some text"
  • Arrays: written in brackets with comma-separated elements: [10,20,"some text","other text",30]
  • Objects: written in braces with key:value pairs: {key1:"Some text",key2:123.4,key3:[10,20,30]}

Note that there is no boolean type: 0 is used for false and 1 for true. Examples:

ASSIGN myNumber, 10
ASSIGN myText, "hello"
ASSIGN myList, [10, 20, 30]
ASSIGN myObject, {key1: 20, key2: "hello"}
ASSIGN mixed, [10, {key: "data"}, 30]

Access via paths in their SNA
The SNA associated with these variables are P$ (for ASSIGN) and X$ (for SAVEVALUE). But since variables can now be more than numbers, SNAs become more versatile so you can access any part of a variable. Access is guided by a path of keys separated by dots, both for arrays and objects:

ASSIGN grades, [8,4,5]
ASSIGN avg, (P$(grades.0) + P$(grades.1) + P$(grades.2)) / 3
ASSIGN grades, {examGrade1:8,examGrade2:4,examGrade3:5}
ASSIGN avg, (P$(grades.examGrade1) + P$(grades.examGrade2) + P$(grades.examGrade3)) / 3

And all of this can become as complex as needed by embedding SNAs anywhere in the notation to build the right path:

ASSIGN number_0,0
ASSIGN number_1,1
ASSIGN number_2,2

ASSIGN grades, {examGrade_0:8,examGrade_1:4,examGrade_2:5}
ASSIGN avg, (P$(grades.examGrade_P$number_0) + P$(grades.examGrade_P$number_1) + P$(grades.examGrade_P$number_2)) / 3

Or accessing an array inside an object, or an object inside an array, following the same approach:

ASSIGN group, [{name: "Luis"}, {name: "Marta"}]
ASSIGN firstName, P$(group.0.name)

There is a single reserved word for these paths: LENGTH

ASSIGN length, P$(anArray.LENGTH)

Partial modification via paths
You can also modify part of a structure by addressing it directly:

ASSIGN anArray.0, {key1: "text1"}

turning the first array element into an object.

SNA for access without evaluation: V$
While P$ and X$ evaluate contents to be displayed, V$ returns the raw content (number, string, object, or array) without any processing. This is necessary to pass a whole array or object through a parameter or to make perfect copies.

; make a copy:
ASSIGN students,[{name:"Ana",age:20},{name:"Alberto",age:22},{name:"Antonio",age:19}]
ASSIGN studentsCopy, V$(students)

; get a specific element
ASSIGN element, V$(anArray.1)

; or pass it as a parameter
CALL goToClass, V$(anArray.1)

It is important to distinguish P$someText from V$someText.

ASSIGN myName,"Antonio"
MOVE {name:text1,text:"My name is P$myName"} ; shows 'My name is Antonio'
MOVE {name:text1,text:"My name is V$myName"} ; shows 'My name is "Antonio"'

This difference exists precisely because V$ retrieves the raw datum, which includes the type declaration—in this case, a string.
V$ should not be used directly inside strings. It is reserved for contexts where a structured value is expected.

As a final note, null handling is done with the "?" operator, so you can assign a value if it has not been assigned before with:

ASSIGN max_value, P$max_value ? P$max_value : 100

 

Example

/* Structured variables: Arrays and Objects
Declaration, access, and modification of complex data.
*/

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

INITIAL posY,400
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}

START 1

;*****************************************************************

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

; --- Declarations of all types ---
ASSIGN myNumber, 10 * 2
ASSIGN myText, "Result"
ASSIGN myArray, [10, 20, 30]
ASSIGN myObject, {key1: 222, key2: 333}
ASSIGN myArrayOfObjects, [10, {key1: 555, key2: (111 * 6)}, 30]

; --- Path-based access ---
ASSIGN sum, P$(myArray.0) + P$(myArray.1)

; --- Path-based modifications ---
ASSIGN myArray.2, 777
ASSIGN myObject.key1, {depth: "inner value"}
ASSIGN myObject.key2, V$(myArray.2)

; --- Raw-value copies (entire structures) ---
ASSIGN objectCopy, V$(myObject)
ASSIGN copiedElement, V$(myArrayOfObjects.1)

; --- Length evaluation ---
ASSIGN arraySize, P$(myArrayOfObjects.LENGTH)

; --- Display ---
MOVE {NAME:Text1, TEXT: "myNumber = P$myNumber"}
MOVE {NAME:Text2, TEXT: "myText = P$myText"}
MOVE {NAME:Text3, TEXT: "myArray.2 = P$(myArray.2)"}
MOVE {NAME:Text4, TEXT: "myObject.key1.depth = P$(myObject.key1.depth)"}
MOVE {NAME:Text5, TEXT: "myObject.key2 (copied) = P$(myObject.key2)"}
MOVE {NAME:Text6, TEXT: "myArrayOfObjects.1.key2 = P$(myArrayOfObjects.1.key2)"}
MOVE {NAME:Text7, TEXT: "objectCopy.key2 = P$(objectCopy.key2)"}
MOVE {NAME:Text8, TEXT: "copiedElement.key1 = P$(copiedElement.key1)"}
MOVE {NAME:Text9, TEXT: "Array length = P$arraySize"}

ADVANCE 100,0 {TO:POS1}
ENDGENERATE 1