LYNX ENGINE

API REFERENCE

JavaScript Reference

A compact reference of the API actually registered in the engine's QuickJS runtime.

Actor

MemberReadWriteDescription
id✓✓Actor identifier.
className✓—C++ class name.
valid✓—Wrapper validity.
entity✓—ECS entity ID.
transform✓✓Actor transform.
position✓✓Position Vec3.
velocity✓✓Linear velocity.
angularVelocity✓✓Angular velocity.
damping✓✓VelocityComponent damping.
lifetime✓✓Remaining lifetime; null/undefined removes the component.
tags✓—Tag list.
scripts✓—Script list.

Actor Methods

getProperty(name)Read a reflected property.
setProperty(name, value)Modify a reflected property.
hasProperty(name)Check whether a property exists.
destroy()Request Actor destruction.
addTag(tag)Add a tag.
removeTag(tag)Remove a tag.
hasTag(tag)Check a tag.
addScript(path)Attach a script.
removeScript(path)Remove a script.
hasScript(path)Check for an attached script.
call(name, ...args)Call a function in the Actor's scripts.
toString()Return a text representation of the Actor.

Transform

transform.positionVec3 reference to position.
transform.rotationVec3 reference to rotation.
transform.scaleVec3 reference to scale.
transform.clone()Detached transform copy.

Vec3

x / y / zReadable and writable components.
set(x, y, z)Set all three components.
set({x,y,z})Set components from an object.
clone()Return a detached JS object.
toString()Return vec3(x, y, z).

Globals

print(...args)Simple log.
console.log(...args)Normal log.
console.info(...args)Informational log.
console.warn(...args)Warning log.
console.error(...args)Error log.
vec3(a,b,c)Construct a vector value. With one number, x/y/z use the same value.

Level

Level.spawn(className, transform?)Level.find(id)Level.findWithTag(tag)Level.all()Level.count(className)Level.destroy(actor)

Input

Input.pressed(name)Input.held(name)Input.released(name)Input.axis(name)

Engine

Engine.getTimeDilation()Engine.setTimeDilation(value)Engine.setTimeDilation(value, duration)Engine.isPlaying()

Complete example

// scripts/Enemy.js
function BeginPlay() {
  parent.addTag("enemy");
  parent.lifetime = 20;
}

function Update(dt) {
  const player = Level.find("Player");
  if (!player || !player.valid)
    return;

  const direction = player.position.x > parent.position.x ? 1 : -1;
  parent.velocity.x = direction * 2;

  if (Input.pressed("attack"))
    player.call("TakeDamage", 10);
}

function EndPlay() {
  console.log("Enemy removed");
}