DukeSoft
Member
Is anyone familiar with sending buffers back and forth through a JS extension for the HTML5 platform? I can send buffers from GM to libraries using buffer_get_address() - that wil give an ArrayBuffer in Javascript, which is good. But when I return a new buffer (an ArrayBuffer) back into GM, stuff breaks. From JS;
in the GM script;
I just don't know how I can use the GM Buffer functions on that JS arraybuffer
hint: -5 is not correct, and using buffer_read only returns "0"
PS: These are questions I had but i couldn't find, so posting them here for future voyagers looking for the answer:
Callback function from javascript to game maker html5:
Prefix your functions in GM with gmcallback_. This will make sure those functions are not obfuscated. They will be available in your JS extension with gml_Script_ prefixed to it. Example;
In GMS: gmcallback_test
In JS: gml_Script_gmcallback_test(-1, -1, <arguments>);
the arguments bit are the argument0 variables you can use. the first and 2nd -1 are required, don't know exactly what it is, but I think its arguments for "on what instance" to execute the code.
Callbacks are ran twice if the gm script has a with():
Yeah, I had that happen too.
When calling that from JS, the output was:
Fixed it by dropping a "return" within the with statement.
Code:
gml_Script_gmcallback_dsnet_data(-1, -1, arrayBuffer); //which is the exact same object type that came back from GM
Code:
show_debug_message(string(argument2)); // [object ArrayBuffer]
show_debug_message(buffer_get_size(argument2)); // -5
show_debug_message(buffer_tell(argument2)); // -5
show_debug_message(typeof(argument2)); // ptr
show_debug_message(ptr(argument2)); // [object ArrayBuffer]
show_debug_message(buffer_get_address(argument2)); // undefined
show_debug_message(buffer_get_address(ptr(argument2))); // -5
hint: -5 is not correct, and using buffer_read only returns "0"
PS: These are questions I had but i couldn't find, so posting them here for future voyagers looking for the answer:
Callback function from javascript to game maker html5:
Prefix your functions in GM with gmcallback_. This will make sure those functions are not obfuscated. They will be available in your JS extension with gml_Script_ prefixed to it. Example;
In GMS: gmcallback_test
In JS: gml_Script_gmcallback_test(-1, -1, <arguments>);
the arguments bit are the argument0 variables you can use. the first and 2nd -1 are required, don't know exactly what it is, but I think its arguments for "on what instance" to execute the code.
Callbacks are ran twice if the gm script has a with():
Yeah, I had that happen too.
Code:
///gmcallback_test
show_debug_message("Outside with");
with (obj_test) {
show_debug_message("Inside with");
}
Code:
Outside with
Inside with
Inside with