Example Script Lifecycle

Example Script Lifecycle

The lifecycle of the script includes four stages: deployment, two iterations, and edit mode.
In the deployment stage, the execution environment is prepared without actions. In the first iteration, global variables are initialized, and syntax errors are checked. The
onResults
function processes the
Test String
, updates counters, and logs results. The second iteration skips initialization and processes the
Wrong String
, adjusts counters, and logs accordingly. Finally, the script enters edit mode, unloading from memory, with variables set to reinitialize upon redeployment.
console.log("Script loading begin"); let no_match_counter = 0; let match_counter = 0; const match_string = "Test String"; let counter = 0; /** Returns the OutputResult type object * @param {InputResult} inputResult * @returns {OutputResult}*/ export function onResults(inputResult) { console.log("onResult called count: ", counter); counter++; // check first decode for first tool if (inputResult.tools[0].decodes[0] === match_string) { match_counter++; } else { no_match_counter++; console.error("No match string find!"); return { common: "Match count: " + match_counter + " No match count: " + no_match_counter }; } console.log("Script loading end")
There are four main stages in the lifecycle of a script:
  1. Deploy the job to initialize the script's execution environment.
  2. Iteration 1:
    1. The code outside the
      onResults
      the function is executed. The global variables
      no_match_counter, match_counter, match_string
      and
      counter
      are created and initialized. The
      console.log
      functions are executed. Any syntax errors in the script are reported at this stage, and its execution is performed if errors are detected.
    2. The
      onResults
      the function is executed. Assume that in this iteration, the read code contains a string.g
      Test String
      .
    3. Values are set, and logs are sent during this stage.
      1. The following string is sent to all available communication channels:
        Match count: 1 No match count: 0
      2. Aurora Focus receives logs in the following order:
        Script loading begins
        ,
        Script loading end
        ,
        onResult called count: 0
      3. Global variables at the end of the script are as follows:
        no_match_counter = 0
        ,
        match_counter = 1, counter = 1
  3. Iteration 2:
    1. No initialization phase.
    2. The
      onResults
      the function is executed. Assume that in this iteration, the read code contains the string.g
      Wrong String
      .
    3. Values are set, and logs are sent during this stage.
      1. The following string is sent to all available communication channels:
        Match count: 1 No match count: 1
      2. Aurora Focus receives logs in the following order:
        onResult called count: 0
        and
        No match string find!
        . The second log belongs to a different category, as noted in the editor console.
      3. Global variables at the end of the script are as follows:
        no_match_counter = 1
        ,
        match_counter = 1, counter = 2
  4. Edit the job and unload the script from memory.
During the next deployment, the variables from Step 2a are initialized.
Each execution is always the first one when using an emulator or performing jobs on the camera while editing.