• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Asynchronous support on HTML5?

Freddy Jones

Your Main Detective
I've done a google search, and also looked a bit on the Yoyogame's help area.

There seems to be documentation on a few modules, but there appears to be none on JavaScript. I'm referring to this post by Nocturne where he's discussing how to access the social asynchronous functionality when making extensions. Is there any known way to use the asynchronous functionality with JavaScript? It would be far more advantageous and convenient than having synchronous checking or checking for responses at all.
 

FrostyCat

Redemption Seeker
You can create scripts with names starting in gmcallback_, then use them as part of callbacks. Remember to convert any non-numeric, non-string values back into numbers and strings (e.g. JSON.stringify() for arrays and objects), since GML can't handle anything else in JS as-is.
 

Freddy Jones

Your Main Detective
You can create scripts with names starting in gmcallback_, then use them as part of callbacks. Remember to convert any non-numeric, non-string values back into numbers and strings (e.g. JSON.stringify() for arrays and objects), since GML can't handle anything else in JS as-is.
Thanks, FrostyCat! That should work just as well!

Just because I'm not exactly sure how that would work. I'll just put this here to be sure.

So if we have this code, what you're saying is I can use a GML script as a first class function?

This would be the javascript function
Code:
    function logMyClick( gmFunction ){
      document.onclick = function(e){
        gmFunction(e.timeStamp);
      };
    }
This would be the GML script
Code:
///gmcallback_logMe( message )
var message = string(argument0);
show_debug_message(message);
Then using the extension would be something like this?
Code:
myClickExtension( gmcallback_logMe); // every click console is filled with timestamp
EDIT: Nothing I've tried for an hour or so straight has worked. Can't get functions to pass for the life of me. Can't seem to find any javascript functions that can get the script for me, or anything of the sort. All that's passed is the Script's index even with that prefix on the GML script or the JS function. I can't find any documentation on what you mentioned, even with specific searches on google.

EDIT2: Made a workaround(chrome only), but seems very hacky. I hope this isn't similar to what you meant:
Code:
var GMLFunction = function(name){
  return window["gml_Script_"+name];
}

function clickMove(script ){
  var callback = GMLFunction(script);
  var self = arguments.callee.caller.arguments[0];
  var other = arguments.callee.caller.arguments[1];
  document.onclick = function(e){
    callback( self, other, e.clientX, e.clientY);
  };
}
 
Last edited:

FrostyCat

Redemption Seeker
@Freddy Jones:

You're right, I just tried it on a test project (1.4.1757) and it looks like they broke it again. For something that's only mentioned in a small corner of clickable_add()'s Manual entry, I wouldn't be surprised if it slipped under the radar untested.

For the meanwhile, you can use gmCallback instead, which uses a hack similar to yours but with better IE handling. It will require you to make minor hacks to the scripts being called, but it does work for sure.
 

Freddy Jones

Your Main Detective
@Freddy Jones:

You're right, I just tried it on a test project (1.4.1757) and it looks like they broke it again. For something that's only mentioned in a small corner of clickable_add()'s Manual entry, I wouldn't be surprised if it slipped under the radar untested.

For the meanwhile, you can use gmCallback instead, which uses a hack similar to yours but with better IE handling. It will require you to make minor hacks to the scripts being called, but it does work for sure.
@FrostyCat Thanks for the help, nonetheless! Saved me from not having any access asynchronous functionality!

I read his code, but I'm fairly contempt with mine. I don't have any problems or have to change my scripts to work with it, and arguments are supported as well. Looking at how his was written, I don't see how it could have better support on IE if he too is still using arguments.callee. I could be wrong, however.

Mine works on Chrome, FireFox, and Edge. Not sure when major browsers will completely drop support for the deprecated arguments.callee, though; doesn't look soon. It is a hack anyhow(mine and his) and hopefully, Studio will have better support regarding this functionality in the future.

I have an updated version which is a lot more practical and reusable if anyone wants to implement in their JS extensions, it's pretty convenient and fast:
https://jsfiddle.net/0ou7p573/
 
S

Sinaz20

Guest
@Freddy Jones could you elaborate on a use case for your code. I'm having a little trouble understanding the comments.

I'm in a similar boat, and just wrote an extension that piggy backs on the gmCallback extension. Wanted to better understand your implementation to get a little more breadth on my knowledge here.

EDIT: also, are you actually hijacking gm's async functionality in any way? Is there a way to invoke an async event in objects that I'm not finding in the documentation?
 
Top