The specific APIs for instances depends on the plugin type. These interfaces are all documented in the scripting reference section of the manual, such as ISpriteInstance for Sprite instances, which provides APIs for things like animations. Note that these interfaces also inherit from IWorldInstance and IInstance (depending on the kind of plugin). For example common properties like x
and y
are part of IWorldInstance
.
Integrating scripts and events
Strings and numbers can be exchanged between event sheets and JavaScript code using global and local variables in event sheets. Local variables are accessible via localVars
inside scripts in event sheets, and global variables are accessible via runtime.globalVars
. There is more information in the manual section on Scripts in event sheets.
Strings and numbers can also be exchanged via instance variables via the instVars
property of IInstance.
See also the example project Integrating events with script for an example of some useful techniques.
Using an external editor
Construct has special features to let you use an external code editor like VS Code to write your project's code if you prefer. See the guide Using an external editor.
Learn more
Here are some more resources to learn more about using JavaScript in Construct.
Examples
There are lots of example projects using JavaScript coding in Construct which you can find in the Scripting category in the Example Browser.
Debugging
You can still use the browser developer tools to debug JavaScript code that you write in Construct. For a quick-start guide on debugging, see the manual section on Debugging script.
Minifying
Minifying on export also applies to your JavaScript code written in Construct. Code minification is done with Google's Closure Compiler, an industry-standard tool. Simple minify mode should never affect how your code runs. However if you enable Advanced minify mode on export, you may need to adjust how you write your code. See the manual guide on Exporting with Advanced minification for more details.
Worker mode
Construct is capable of running its entire engine in a Web Worker, rendering via OffscreenCanvas. However by default projects using JavaScript code run in the main page ("DOM mode") to ensure compatibility with code that expects to be able to use DOM features like document
. If your JavaScript code is compatible with running in a Web Worker, you can re-enable worker mode for improved performance by changing the project property Use worker to Yes (in the Advanced section). There is more information about this in the manual section JavaScript in Construct.
Reference
See the Scripting section of the manual for full documentation on using JavaScript in Construct.
TypeScript
Construct also supports writing code in TypeScript, which is an extension of JavaScript that adds static types. This can provide improved tooling such as better autocomplete. See the guide Using TypeScript in Construct to learn more.