Procedure-based modification

Updated: 2025-09-15

Before introducing the CX$ context system to instantiate reusable graphic components in independent libraries, it is important to understand how a visual component can be built manually, step by step, using procedures (PROCEDURE) and configuration structures (INITIAL).

This example does not represent the optimal or recommended way to implement reusable graphic components, but it plays an essential role in learning:

  • It helps you understand how grouped graphics are declared (GROUP).
  • It shows how to parameterize geometry and position using dictionaries (INITIAL).
  • It teaches how to encapsulate visual transformations inside procedures.
  • It introduces calling “visual functions” from entities using CALL.

This approach will later be replaced by using CX$ contexts, but it’s worth mastering this “manual” level first to understand in depth how GPSS-Plus turns procedures into autonomous, reusable visual components.

In this example, we render a tank with a visual level, made of a GROUP that contains:

  • an outer frame (closed LINE)
  • a fill level (closed LINE, with variable height)
  • a text showing the visible fill percentage

All the tank’s geometry and position are defined via a configuration structure (config) and applied directly to graphics with fixed names. Although this simulates a form of parameterization, it is not reusable as-is: the graphic object names are hard-coded, which prevents instantiating multiple tanks without conflicts.

This limitation will be solved later with CX$ contexts and libraries, which will allow creating multiple visual instances of the same component, each with its own state and configuration.

The nivel_init procedure generates the graphic vertices at startup (PRE_RUN), and deposito_set visually updates the fill level based on a percentage (P$PARAM_A).

deposito_locate is also included, allowing you to move the whole group to a new position.

Example

/*

 Graphics. Procedure-based modification
 
*/
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}


;==============================
; TANK CONFIGURATION
;==============================
INITIAL config, {deposito_coords:[0, 0, 20, 200],deposito_position:[180,180]} 

;==============================
; GRAPHICS
;==============================
GRAPHIC {NAME:Deposito, TYPE:GROUP, X:0, Y:0}

; Outer frame
GRAPHIC {
  NAME:Marco,
  GROUP:Deposito,
  TYPE:LINE,
  POINTS:"[0,0],[0,10],[10,10],[10,10]",
  COLOR:#555555,
  CLOSE:1
}

; Inner level (fill)
GRAPHIC {
  NAME:Nivel,
  GROUP:Deposito,
  TYPE:LINE,
  POINTS:"[0,300],[0,300],[40,300],[40,300]",
  COLOR:#3399FF,
  FCOLOR:#99CCFF,
  CLOSE:1
}

; Percentage text
GRAPHIC {
  NAME:TextoNivel,
  GROUP:Deposito,
  TYPE:TEXT,
  X:0, Y:0,
  TEXT:"Level: 0%",
  COLOR:#000000
}
START 100


PROCEDURE PRE_RUN
	timeout nivel_init,0
	TERMINATE 
ENDPROCEDURE 1

;==============================
; UPDATE PROCEDURE
;==============================
PROCEDURE nivel_init
move {name:Marco
	,X1:X$(config.deposito_coords.0)-4,Y1:X$(config.deposito_coords.1)-4
	,X2:X$(config.deposito_coords.2)+4,Y2:X$(config.deposito_coords.1)-4
	,X3:X$(config.deposito_coords.2)+4,Y3:X$(config.deposito_coords.3)+4
	,X4:X$(config.deposito_coords.0)-4,Y4:X$(config.deposito_coords.3)+4
	}

move {name:Nivel
	,X1:X$(config.deposito_coords.0),Y1:X$(config.deposito_coords.1)
	,X2:X$(config.deposito_coords.2),Y2:X$(config.deposito_coords.1)
	,X3:X$(config.deposito_coords.2),Y3:X$(config.deposito_coords.3)
	,X4:X$(config.deposito_coords.0),Y4:X$(config.deposito_coords.3)
	}

MOVE {NAME:TextoNivel
		, x:(GD$(Marco,X1) + GD$(Marco,X2))/ 2
		, y:X$(config.deposito_coords.1)-14, TEXT:"Level: PP$A%"}

MOVE {NAME:Deposito
		, x:X$(config.deposito_position.0)
		, y:X$(config.deposito_position.1)}   
terminate
endprocedure 1


PROCEDURE deposito_set

; PP$A = desired percentage (0 to 100)

ASSIGN yBase, X$(config.deposito_coords.1) ; bottom y
ASSIGN yTop, X$(config.deposito_coords.3)  ; top y

ASSIGN alturaMaxima, P$yBase - P$yTop
ASSIGN alturaNivel, P$alturaMaxima * P$PARAM_A / 100
ASSIGN yActual, P$yBase - P$alturaNivel

; Move the level vertices
MOVE {
  NAME:Nivel,
  Y3:P$yActual,
  Y4:P$yActual
}
MOVE {NAME:TextoNivel,TEXT:"Level: P$PARAM_A%"}

ENDPROCEDURE 1

PROCEDURE deposito_locate

MOVE {NAME:Deposito
		, x:P$PARAM_A
		, y:P$PARAM_B}   
        
ENDPROCEDURE 1

;==============================
; ENTITY THAT USES IT
;==============================
GENERATE 25,0 {NAME:Gen1}

CALL deposito_set, 25
ADVANCE 5

CALL deposito_set, 50
ADVANCE 5

CALL deposito_set, 75
ADVANCE 5

CALL deposito_set, 90
ADVANCE 5

CALL deposito_set, 10
ADVANCE 5
CALL deposito_locate, GD$(Deposito,X)+4,GD$(Deposito,Y)+4

TERMINATE 1