After recently starting work on a new HTML5 project, I came to the realisation that it was completely unnecessary to constantly poll for certain events with GML (In my case, the DOM Event 'onResize').

gmCallback is a HTML5 extension that allows you to call GameMaker scripts using external Javascript, without the need for constant polling, and regardless of obfuscation. This has a whole range of uses, such as executing GML scripts on DOM events, writing asynchronous Javascript extensions and easier interaction with the HTML5 application (Such as with HTML input buttons).

What you've done with this extension, is smart. I haven't thought about such possibility to utilize Function properties.May I ask what is the purpose of _define script, though? There's no functional code in that, and result isn't used in example. Perhaps you could just mention that scripts should be called once before usage.Also could make an instance of Function,

new Function(code)

instead of using eval ()

Either way, a very nice extension.

1

If my posts contain broken links, try looking around my website. I gradually make blog posts for any examples I make.

True, callback_define_script() originally served no real purpose besides initially calling the specified GameMaker script. However I decided to do it this way, since it makes the GML code much more readable. It should work perfectly fine though if you wish to omit callback_define_script(), and instead just call each script once to initialise.

The function became slightly more useful though when I added the return value to indicate whether initialisation was successful or not. It's not taken advantage of in the example, but you could easily add a check to make sure loading didn't fail. (Which is possible given the wide range of browsers in use)

I'll admit, I hadn't considered using new Function() over eval. For the time being though I'll leave it how it is, since new Function() seems to create anonymous functions - which might be of some disadvantage during debugging. Unless there's a significant advantage to changing it that I'm unaware of?

GM:Studio unable to load those type of files. Unless I'm missing something of how extensions work?

The '.gmz' file is a Compressed GameMaker file, open it from the Import tab on the Studio welcome screen. The '.gex' file is the extension package, you can install it from within GameMaker (Ctrl+Shift+E).

Very good!!! now im going to test this extension :-D! edit: work well :-D good work! but how arguments? it can be very useful...

I'd originally been using JavaScript global variables to pass any information required to the GameMaker scripts, however I recently came upon a situation where this wasn't ideal. So, I've decided to add support for arguments. You can download the new version of gmCallback from the original post; I've also updated the example and the help file to reflect the changes.

Can anyone get this extension working with version 1.3 of game maker studio? Getting the error "wrong number of arguments to function or script" when trying to use "callback_script("example",1))"

Please help!

Hey, THE_T_V1RUS,

Stumbled upon the same issue today (though in my case it was the second function of the extension: callback_script_defined() ). Try deleting this function from resource tree and then adding it again. But this time leave "Use variable amount of arguments" checked, and, thus, do not add any arguments. Worked for me!