Strata - v1.4.10
    Preparing search index...

    Function conditionalSystem

    • Creates a conditional system that only runs when a predicate is true.

      Enables dynamic system control based on game state. More flexible than manual enable/disable as the condition is evaluated every frame.

      Type Parameters

      Parameters

      • predicate: () => boolean

        Function that returns whether to run the system

      • system: SystemFn<T>

        The system function to conditionally run

      Returns SystemFn<T>

      A system that only executes when predicate returns true

      // Only run movement when game is not paused
      const gameState = { isPaused: false };
      const pausableMovement = conditionalSystem(
      () => !gameState.isPaused,
      movementSystem
      );
      // Run AI only when there are enemies
      const aiSystem = conditionalSystem(
      () => countEntities(world, 'enemy') > 0,
      enemyAI
      );