Skip to content

Latest commit

 

History

History
82 lines (59 loc) · 3.17 KB

File metadata and controls

82 lines (59 loc) · 3.17 KB

API Functions

In order to simplify and improve developer experience, functions have been added to allow manipulation of the game world by developers.

Basics

API functions are divided into three, each differ in their usage.

node: used to manipulate objects (e.g. mass)
game: used to manipulate the game world (e.g. play sounds)
mesh: Returns properties of the parent mesh

API functions tend to require uuids of the target objects to run, which can be found on the properties window on the right side of the screen.

The node Object

node.setColor(uuid: String, color: String)

   Used to manipulate object color.
   Example: node.setColor("ZYG06", "#F54927")

node.setPosition(uuid: String, xpos: Number, ypos: Number, zpos: Number)

   Used to manipulate object position.
   Example: node.setPosition("ZYG06", 0, 2, 0)

node.setSize(uuid: String, xsize: Number, ysize: Number, zsize: Number)

   Used to manipulate object size.
   Example: node.setSize("ZYG06", 2, 2, 2)

node.setRotation(uuid: String, x: Number, y: Number, z: Number)

   Used to manipulate object rotation.
   Example: node.setRotation("ZYG06", 0, 3.14, 0)

node.setMass(uuid: String, mass: Number)

   Used to manipulate object mass.
   Example: node.setMass("ZYG06", 1)

The game Object

game.setMenu(id: String, text: String)

   Used to add a text element to the game menu.
   id - unique identification key for accessing the element.
   Example: game.setMenu("points", `Your Points: ${x}`)

game.sendLocalMessage(text: String)

   Used to send a local message (only applies to client).
   Example: game.sendLocalMessage("3.14 is a funny number")

game.playAudio(url: String)

   Used to play an audio track.
   Example: game.playAudio("https://example.com/audio.mp3")

game.spawnMesh(type: String, sizeX: Number, sizeY: Number, sizeZ: Number, x: Number, y: Number, z: Number, mass: Number)

   Spawns an object and returns its ID.
   type - Type of mesh (refer to elemTypes in addShapes.js for mesh types)
   Example: game.spawnMesh("cube", 1, 1, 1, 0, 2, 0, 0)

game.deleteMesh(uuid: String)

   Deletes an object.
   Example: game.deleteMesh("ZYG06")

game.createListener(uuid: String, type: String, callback: Function)

   Listens to a mesh for an event. Only runs callback once.
   type - Only click for now
   Example: game.createListener("ZYG06", "click", () => { console.log("boom"); })

The mesh Object

mesh.getUUID()

   Returns the parent mesh UUID

mesh.getPosition()

   Returns the parent mesh position

mesh.getMass()

   Returns the parent mesh mass

mesh.getColor()

   Returns the parent mesh color

mesh.getSize()

   Returns the parent mesh size

mesh.getRotation()

   Returns the parent mesh rotation