Dragonfly Cloud is now available in the AWS Marketplace - learn more

Question: Does GameMaker use JavaScript?

Answer

GameMaker Studio uses its own scripting language called GameMaker Language (GML). However, GameMaker Studio 2.x introduced the ability to use JavaScript for certain aspects of game development when exporting to HTML5. This means that while GML is primarily used for game logic within the GameMaker environment, developers can utilize JavaScript for web-specific functionality or for extending their games on web platforms.

For example, integrating with web APIs or adding additional HTML5 features might involve writing some JavaScript code. Nonetheless, GML remains the core scripting language for GameMaker and is used for all platforms, not just HTML5.

Here is a basic example of how you might call a JavaScript function from GML:

// Create a JavaScript function to alert a message var js_code = "function showMessage(message) { alert(message); }"; html5_run_javascript(js_code); // Call the JavaScript function from GameMaker html5_run_javascript("showMessage('Hello from GameMaker!');");

In this code snippet, we first define a JavaScript function showMessage using html5_run_javascript. This function simply shows an alert with a given message. We then call the showMessage function with a string parameter from GML. The html5_run_javascript function is used to run arbitrary JavaScript code from within GML when running the game in an HTML5 module.

Keep in mind that this integration is specifically for the HTML5 export module and JavaScript code will not work when exporting to other platforms that GameMaker supports.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Switch & save up to 80% 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement. Instantly experience up to a 25X boost in performance and 80% reduction in cost