Blog post: (link)
This extension uses fact that JavaScript functions can be legally created from string to open a 'gate' from GameMaker:HTML5 (and HTML5 runner of Studio) to JavaScript.
To explain it simple, think of it as execute_string variant. Except in other language. And at times more powerful than GML.
Installation: Include extension in project.
Functions:
dj_init - resets all currently loaded functions in extension.
dj_add(name, code) - adds a new function to index.
Index can be both number or string.
Parameter 'code' is JavaScript code, to be contained in function.
Code can be also created dynamically (same as you would do with execute_string)
dj_call(name) - calls loaded function, returning it's value.
dj_addN(index, ..., code) - similar to dj_add, but allows to specify names of parameters.
With those, you will be able to access them by given names in function.
dj_callN(index, ...) - to be used in pair with above, calls function, providing it given parameters.
dj_exists(index) - returns if a function is bound to given index.
dj_count() - returns total number of functions loaded at the moment.
dj_run(code) - creates and executes piece of code without storing it anywhere. Is intended to be used with functions that are used only once through the game or are not worth storing.
Examples:
Add line of text to GameMaker debug console:
dj_run("document.getElementById( 'debug_console').value += 'Found by JavaScript.\n';")Create and use a function to change page's background color:dj_add3('color', 'r', 'g', 'b', "document.body.style.backgroundColor = 'rgba('+r+ ','+g+ ','+b+ ',1)';");
dj_call3('color', 64, 64, 64);Create function from concatenated strings:index = 'some'
dj_add('get_' + index, "return '" + index + "';")
show_message(dj_call('get_some'))Remarks:
* It is quite easy to crash your game with this extension, since errors are not handled anyhow by default.
I've actually removed that because it was hard to determine why something was not working with errors being ignored silently.
JavaScript errors are sent to debug console, which can be accessed in Chrome and Internet Explorer by pressing F12, Ctrl+Shift+I in Opera, and F12 in Firefox after installing Firebug or equivalent extension.
* Other loaded functions can be accessed as 'dj_data[index](...)'.
* It is recommended that you do not include line breaks in loaded code (either wrap lines by "'+(next line)+'", or string_replace_all them) - mis-matches in string format between loaded string and game itself may cause errors.
* While this allows 'dynamic' code, there is no defined way to access in-game resources without embedding them into functions or passing them as arguments.



Find content
Male



