The object passed as harness to a gameplay test script.

Constructors

Methods

  • The camera of a layer (JSON-safe), or null if the layer does not exist. angle is the 2D rotation (the yaw of the view, same convention as object angles). rotationX/rotationY are the 3D camera rotations: rotationX is 0 looking straight down (the 2D default) and 90 at the horizon, so the pitch of a first-person view is rotationX - 90 (positive = looking up).

    Parameters

    • layerName: string = ''

    Returns null | {
        angle: number;
        rotationX: number;
        rotationY: number;
        x: number;
        y: number;
        z: number;
        zoom: number;
    }

  • Get a variable of an object (same entry shape as getSceneVariable), or undefined if the object or the variable does not exist.

    Parameters

    • objectIdOrName: string | number

      An instance id (from getObjects) or an object name (first instance).

    • variableName: string

    Returns undefined | VariableNetworkSyncData

  • The sounds and musics played during the test so far, with the frame they were played at - a direct signal that a mechanic fired (a pickup, a shot, an explosion...).

    Returns {
        frame: number;
        sound: string;
    }[]

  • Get the position of a target (an object or a position) relative to the first instance of referenceObjectName (2D and 3D). Deciding how to move toward the target with the game's actual controls is the job of the test script (use resetSceneAndProbeControls to discover the controls, makeProgressTracker to detect a lack of progress).

    Parameters

    • referenceObjectName: string
    • target: {
          id?: number;
          name: string;
      } | {
          x: number;
          y: number;
          z?: number;
      }
    • Optional options: {
          fromCamera?: string;
          fromZ?: number;
          heading?: number;
          reachRadius?: number;
      }
      • Optional fromCamera?: string

        Measure from the camera of this layer (position, yaw and pitch) instead of the object: what a first-person view aims with.

      • Optional fromZ?: number

        Measure from this Z instead of the object's center Z (an eye or muzzle height).

      • Optional heading?: number

        Compute yawDiff against this heading (in degrees) instead of the object's angle - for turrets and weapons with their own rotation.

      • Optional reachRadius?: number

    Returns null | GameplayTestRelativePosition

  • The raw gdjs.RuntimeObject of an instance, or null if not found. Behaviors can be reached with getBehavior(behaviorName) (also null if not found). Prefer the harness APIs (snapshots, inputs...) - direct mutations can invalidate what the test asserts.

    Parameters

    • objectIdOrName: string | number

      An instance id (from getObjects) or an object name (first instance).

    Returns null | RuntimeObject

  • Load and start the given scene, replacing any running scene.

    Parameters

    • sceneName: string
    • Optional options: {
          skipCreatingInstances?: boolean;
      }
      • Optional skipCreatingInstances?: boolean

    Returns Promise<void>

  • Check if the straight segment between the first instance of referenceObjectName and the first instance of targetObjectName is clear of the given blocker objects. 2D ONLY: the test uses the 2D hitboxes in the X/Y plane and ignores Z.

    Parameters

    • referenceObjectName: string
    • targetObjectName: string
    • blockerObjectNames: string[]

    Returns {
        blockedAt?: {
            x: number;
            y: number;
        };
        blockedBy?: string;
        clear: boolean;
    }

    • Optional blockedAt?: {
          x: number;
          y: number;
      }
      • x: number
      • y: number
    • Optional blockedBy?: string
    • clear: boolean
  • Turn the first instance of referenceObjectName toward the target, by applying mouse movement deltas (FPS/pointer-lock style, yaw and pitch in 3D) until it is aiming at it. The aim is measured on the camera of the object's layer when it is a 3D one (the ground truth of a first-person view: right eye height, right rotations whatever the game drives to move it - see measuredFrom in the result), with a fallback to the object's own rotations. The mouse sensitivity and direction of the game are measured and adapted to live, per axis. When the vertical aim shows no measurable response, the vertical input is undone and the aim falls back to yaw-only, reported as sawPitchResponse: false. Returns null if the object or the target is missing.

    Parameters

    • referenceObjectName: string
    • target: {
          id?: number;
          name: string;
      } | {
          x: number;
          y: number;
          z?: number;
      }
    • Optional options: {
          fromCamera?: string;
          toleranceDegrees?: number;
          yawOnly?: boolean;
      }
      • Optional fromCamera?: string
      • Optional toleranceDegrees?: number

        Consider the aim done when both angles are within this tolerance (default 3 degrees - lower it to hit a small or far target).

      • Optional yawOnly?: boolean

    Returns Promise<null | GameplayTestAimResult>

  • Make a tracker measuring the progress of the first instance of referenceObjectName toward a target (the distance is 3D when the object has a Z coordinate). Call update() regularly (e.g. once per loop iteration): it reports the current distance, whether the target is reached, and whether progress stalled (distance shrank by less than minProgress over the last windowFrames frames - time to try an escape strategy). The first update of a stall also records a stuck event in the event log. Call reset() after switching to another target.

    Parameters

    • referenceObjectName: string
    • target: {
          id?: number;
          name: string;
      } | {
          x: number;
          y: number;
          z?: number;
      }
    • Optional options: {
          minProgress?: number;
          reachRadius?: number;
          windowFrames?: number;
      }
      • Optional minProgress?: number
      • Optional reachRadius?: number
      • Optional windowFrames?: number

    Returns GameplayTestProgressTracker

  • Measure what each key actually does to the first instance of objectName (2D and 3D: dz is measured when the object has a Z coordinate): for the baseline (no key) and then each key, the scene is restarted, the key held for frames frames, and the displacement (net + extremes: a jump shows as a negative minDy even if the object lands back) and yaw change are measured. Compare each key's result to baseline (gravity or idle drift affects both). The scene is restarted again at the end, so call this BEFORE the scenario of the test. An entry is null if the instance disappeared during that probe.

    Parameters

    • objectName: string
    • keyNames: string[]
    • Optional options: {
          frames?: number;
      }
      • Optional frames?: number

    Returns Promise<{
        baseline: null | GameplayTestControlProbeResult;
        keys: {
            [keyName: string]: GameplayTestControlProbeResult | null;
        };
    }>

  • Press or release a keyboard key. Accepts GDevelop event-sheet key names ("Left", "Space", "a"...) and Web API names ("ArrowLeft"...).

    Parameters

    • keyName: string
    • pressed: boolean

    Returns void

  • Move the mouse cursor to a position, expressed in the scene coordinates of the given layer (pass the layer of the object you want to point at).

    Parameters

    • x: number
    • y: number
    • layerName: string = ''

    Returns void

  • Move the instance with the given id to a position. Use for test setup only. The move takes effect immediately (physics bodies included), but the game's logic keeps acting on the object each stepped frame (forces, AI...): to hold an object somewhere, re-apply the position every frame via onFrame.

    Parameters

    • id: number
    • x: number
    • y: number
    • Optional z: number

    Returns void

  • Set a variable of an object (number, string or boolean). Use for test setup only. Throws if the object does not exist.

    Parameters

    • objectIdOrName: string | number

      An instance id (from getObjects) or an object name (first instance).

    • variableName: string
    • value: string | number | boolean

    Returns void

  • Step the given number of game frames.

    Parameters

    • frameCount: number
    • Optional options: {
          dtMs?: number;
          onFrame?: ((context) => void);
      }
      • Optional dtMs?: number
      • Optional onFrame?: ((context) => void)
          • (context): void
          • Parameters

            • context: {
                  frame: number;
              }
              • frame: number

            Returns void

    Returns Promise<void>

  • Step frames until the condition returns true, or maxFrames frames were stepped. Returns true if the condition was met.

    Parameters

    • condition: (() => boolean)
        • (): boolean
        • Returns boolean

    • options: {
          maxFrames: number;
          onFrame?: ((context) => void);
          stuckDetection?: {
              minDisplacement?: number;
              objectName: string;
              onStuck?: ((context) => void);
              windowFrames?: number;
          };
      }
      • maxFrames: number
      • Optional onFrame?: ((context) => void)
          • (context): void
          • Parameters

            • context: {
                  frame: number;
              }
              • frame: number

            Returns void

      • Optional stuckDetection?: {
            minDisplacement?: number;
            objectName: string;
            onStuck?: ((context) => void);
            windowFrames?: number;
        }
        • Optional minDisplacement?: number
        • objectName: string
        • Optional onStuck?: ((context) => void)
            • (context): void
            • Parameters

              • context: {
                    frame: number;
                    x: number;
                    y: number;
                    z: number;
                }
                • frame: number
                • x: number
                • y: number
                • z: number

              Returns void

        • Optional windowFrames?: number

    Returns Promise<boolean>

  • Step until the first instance of the object stops moving: its position changed less than tolerance (default 0.5) per frame for stableFrames (default 20) consecutive frames. Returns whether it settled within maxFrames (default 300). Use this for physics objects instead of a hand-written "read, compare, update" condition in stepUntil (which can silently pass without stepping a frame).

    Parameters

    • objectName: string
    • Optional options: {
          maxFrames?: number;
          stableFrames?: number;
          tolerance?: number;
      }
      • Optional maxFrames?: number
      • Optional stableFrames?: number
      • Optional tolerance?: number

    Returns Promise<boolean>