The specific APIs for instances depends on the plugin type. These interfaces are all documented in the scripting reference section of the manual, such asISpriteInstance for Sprite instances, which provides APIs for things like animations. Note that these interfaces also inherit fromIWorldInstance andIInstance (depending on the kind of plugin). For example common properties likex andy are part ofIWorldInstance.
Note that Construct's expressions are not JavaScript code. You cannot paste something you'd use in a Construct expression in to JavaScript and expect it to work. Refer to the scripting reference for the available features.
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 vialocalVars inside scripts in event sheets, and global variables are accessible viaruntime.globalVars. There is more information in the manual section onScripts in event sheets.
Strings and numbers can also be exchanged via instance variables via theinstVars property ofIInstance.
See also the example projectIntegrating 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 guideUsing 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 theScripting category in theExample 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 onDebugging 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 enableAdvanced minify mode on export, you may need to adjust how you write your code. See the manual guide onExporting 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 likedocument. 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 propertyUse worker toYes (in theAdvanced section). There is more information about this in the manual sectionJavaScript in Construct.
Reference
See theScripting section of the manual for full documentation on using JavaScript in Construct.
TypeScript
Construct also supports writing code inTypeScript, which is an extension of JavaScript that adds static types. This can provide improved tooling such as better autocomplete. See the guideUsing TypeScript in Construct to learn more.