Index

Contraption Maker Modding Guide

For more information, visit the Contraption Maker Wiki

Global Callback functions

There are some global built-in functions that your script can implement. These are called by the game at the appropriate time.

  • onStart(): The onStart function takes no parameters. This is where you can create a UI label.
  • onUpdate(): The onUpdate function takes no parameters. It is called every frame. This is where you could move scenery or the camera.
  • onKeyDown(key): The onKeyDown function takes a single parameter which is the keycode for the key pressed
  • onKeyUp(key): The onKeyDown function takes a single parameter which is the keycode for the key released

Per-part Collision handling

Collision handling is handled on a per part basis. You handle collisions by first assigning a script name in the editor to a part. Then in the script, you can reference that script name to add a collision handler. The named part is automatically exposed to the script engine as a global Javascript object.

Example: you have a ball named "TheBall" in the level. You can handle the ball collision with another ball with this callback. Inside the callback, 'this' refers to the object that is receiving the collision callback. So in this example, this would equal "TheBall".

TheBall.onCollision = function(otherPart)
{
    var otherType = otherPart.getType();
    var thisType = this.getType();
}

General Tips

The version of Javascript that Contraption Maker supports is ECMAScript 5. The Javascript is not running in a browser, so any methods you are used to when writing Javascript to interact with a browser will not work. There is no window object for example to interact with.

Here are some links to tutorials that are relevant within the Contraption Maker modding environment: