Execute A GML Script From A JavaScript Extension

The manual briefly mentions prefixing scripts with the gmcallback_ prefix to permit "clickable" buttons to interact with your games (see the manual, here, for more information). However, the gmcallback_ prefix can also be used to permit JavaScript extensions call GML scripts.

To make a script that will be available to the JavaScript extension simply make sure it is prefixed with gmcallback_, like this for example:

/// @function      gmcallback_hello();
/// @description  Output "Hello World" to the debug console
show_debug_message("Hello World");

The gmcallback_ prefix ensures that GameMaker Studio 2 will not obfuscate the script when the project is compiled and let your Java Script extension access it. However, you don't simply call the script name from your extension. Instead you are required to add another prefix in your JS - gml_Script_. So, in your JS the script given above would be called like this:

// Call the script directly

// Call the script dynamically
var scr = "gmcallback_hello";




Have more questions? Submit a request


Article is closed for comments.