Before starting with contexts, we must take into account a specific characteristic of GPSS-Plus.
In general, drag-and-drop based engines allow resources to be easily placed on the canvas and immediately used. In GPSS-Plus this works differently: the resource must be defined by writing its command.
On the other hand, this drag-and-drop approach makes runtime resource creation very difficult. In GPSS-Plus this is solved by simply replacing the FACILITY command with the NEWFACILITY block.
The only requirement is that the resource must exist before being used, which is why this is typically done in PRE_RUN.
Example
/*
Contexts and modules. Dynamic creation 1
*/
SYSTEM {TYPE:OPTIONS, SPEED:5}
SYSTEM {TYPE:PRE_RUN,TRIGGER:PRE_RUN}
Position {NAME:pos_exit,X:581,Y:407}
; --- Facility defined in the classic way ---
FACILITY {NAME:resource_static, CAPACITY:1, X:496, Y:164}
START 200
PROCEDURE PRE_RUN
; Create a second dynamic facility at startup
NEWFACILITY {NAME:resource_dynamic, CAPACITY:1, X:300, Y:400}
TERMINATE_VE
ENDPROCEDURE
;------------------------------------------------------
; --- Entity flow ---
GENERATE 10,0 {NAME:GEN1} ; one entity every 10 ticks
advance 15 {to:resource_static}
SEIZE resource_static
ADVANCE 15
RELEASE resource_static
advance 15 {to:resource_dynamic}
SEIZE resource_dynamic
ADVANCE 17
RELEASE resource_dynamic
advance 15 {to:pos_exit}
TERMINATE 1