All files / object-instance/variables set-variable-value.function.ts

100% Statements 7/7
100% Branches 1/1
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27              39x 39x                 39x 40x   40x 1x     39x    
/**
 * Exports object instance set variable variable value function.
 *
 * @module object-instance/switches/set-variable-value.function
 */
import type { AgtkObjectInstance } from '@agogpixel/pgmmv-ts/api/agtk/object-instance/object-instance';
 
import { ObjectInstanceAccessorType } from '../object-instance-accessor-type.enum';
import { resolveId } from '../resolve-id.function';
 
/**
 * Set variable value in object instance.
 *
 * @param objectInstance Object instance.
 * @param key Variable ID or name.
 * @param value Value to be set.
 */
export function setVariableValue(objectInstance: AgtkObjectInstance, key: number | string, value: number) {
  const id = resolveId(objectInstance, ObjectInstanceAccessorType.Variables, key);
 
  if (id === -1) {
    return;
  }
 
  objectInstance.variables.get(id).setValue(value);
}