Conditions

Updated: 2025-09-16

Conditions

Models a conditional holding resource.
An entity may pass through immediately or be held depending on whether certain logical conditions are met, both general and entity-specific.

Holding logic:

The resource evaluates three types of conditions:

  • GENERAL EXPRESSION (EXPRESSION)
    Defined on the resource itself (affects all entities).

  • ENTITY-SPECIFIC EXPRESSION
    Specified in the WAITUNTIL block for a specific entity.

  • ABSOLUTE EXPRESSION
    Provided in WAITCHECK, and overrides the others. If it is true, it releases entities.

For an entity to continue, both expressions (GENERAL and ENTITY-SPECIFIC) must be true, unless an ABSOLUTE EXPRESSION is used, which becomes the only releasing condition.

Releasing (or allowing passage) happens through a check. This check occurs whenever an entity is released or when explicitly requested.

Expressions are always written in parentheses.

Internally it manages one list: occupying entities.
This resource is especially useful as a general multi-traffic-light or a shared waiting room for multiple resources together.
Checking can happen every tick or at a fixed interval via a TIMER.
Typically, checks are triggered from the HOOKs of the involved resources.

Associated blocks:

  • WAITUNTIL resourceName[,(entitySpecificExpression)] ; The entity is held if it does not satisfy the ABSOLUTE expression or the ENTITY-SPECIFIC one (if defined).
  • WAITCHECK resourceName[,(absoluteExpression)]; Checks all held entities. If an ABSOLUTE expression is provided, it becomes the only releasing criterion.

Available events: ON_ATTEPMT, ON_CHECK, ON_QUEUE

Conditions {NAME:semaphore, EXPRESSION:(D$N %2 == 1) X:100, Y:100, ON_CHECK:semaphore_check}
;------------------------
WAITUNTIL semaphore; The entity continues if it is odd; (The entity is held if its number is even.)
WAITUNTIL semaphore,(D$N %3 == 0); The entity continues if it is odd and a multiple of 3. (3,9,15...)
;------------------------
WAITCHECK semaphore; Checks all held entities
WAITCHECK semaphore,(1==1) ; Releases all held entities
WAITCHECK semaphore,(D$N %2 == 0) ; Releases all even entities

Example

/*

Resources. Conditions


*/
SYSTEM {TYPE:ON_TIMER, TRIGGER:TIMER1, INTERVAL: 350}
SYSTEM {TYPE:ON_TIMER, TRIGGER:TIMER2, INTERVAL: 650}

POSITION {NAME:Exit,X:615,Y:388}

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}

Conditions {NAME:Conditions1,X:324,Y:160
	,expression:(D$N % 3 == 0)
	,ON_ATTEMPT:Conditions1_ATTEMPT
	,ON_CHECK:Conditions1_CHECK
	,ON_QUEUE:Conditions1_QUEUE
    }


START 100

;-------------------------------

GENERATE 20,0 {NAME:GEN1,X:62,Y:396}

advance 10 {to:Conditions1}

waituntil Conditions1,(D$N!=3)

move {name:Text1,text:"AC1$ I am Entity [D$N] and I move on"}
advance 100,50 {to:Exit}

endgenerate 1
;-------------------------------
PROCEDURE TIMER1
	waitcheck Conditions1,(D$N%2==1)
	move {name:Text6,text:"AC1$ I am TIMER [D$N] WAITCHECK the odd ones"}
	TERMINATE_VE 
ENDPROCEDURE 

PROCEDURE TIMER2
	waitcheck Conditions1,(1==1)
	move {name:Text7,text:"AC1$ I am TIMER [D$N] WAITCHECK ALL"}
	TERMINATE_VE 
ENDPROCEDURE 

PROCEDURE Conditions1_QUEUE
	move {name:Text3,text:"AC1$ I am the VE [D$N] from ON_QUEUE for entity P$ENTITYNUMBER"}
    TERMINATE_VE
endprocedure 
PROCEDURE Conditions1_CHECK
	move {name:Text4,text:"AC1$ I am the VE [D$N] from ON_CHECK for entity P$ENTITYNUMBER"}
    TERMINATE_VE
endprocedure 
PROCEDURE Conditions1_ATTEMPT
	move {name:Text5,text:"AC1$ I am the VE [D$N] from ON_ATTEMPT for entity P$ENTITYNUMBER"}
    TERMINATE_VE
endprocedure 
;-------------------------------