Jump to content


Photo

Gamemaker Callbacks Within Javascript?


  • Please log in to reply
8 replies to this topic

#1 aiacono

aiacono

    GMC Member

  • New Member
  • 13 posts

Posted 24 September 2011 - 07:02 PM

Is there any way to call a game maker function from a javascript extension, such as a callback? A good example:
function gm_Ajax(verb, url, callback) {
$.ajax({type: verb, url: url, complete: callback});
}

From what I know, GML allows strings and doubles. Maybe the callback could be a string and there could be a js function called __gm_call?
  • 0

#2 paul23

paul23

    GMC Member

  • Global Moderators
  • 4147 posts
  • Version:GM:Studio

Posted 24 September 2011 - 07:23 PM

Is there any way to call a game maker function from a javascript extension, such as a callback? A good example:
function gm_Ajax(verb, url, callback) {
$.ajax({type: verb, url: url, complete: callback});
}

From what I know, GML allows strings and doubles. Maybe the callback could be a string and there could be a js function called __gm_call?

This would be incredibly hard, as the obfuscator has to look inside your extensions & change those on obfuscating.
  • 0

#3 Jobo

Jobo

    Second-Scum-Of-The-Earth

  • YoYo Games Staff
  • 3000 posts
  • Version:GM:Studio

Posted 24 September 2011 - 07:29 PM

And actually GM doesn't allow strings. It allows chars.
  • 0

My posts are my own views and opinions... Unless they are yours too, in which case I think you're a very intelligent and handsome individual (I think you are anyway!)


#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 24 September 2011 - 08:48 PM

If script_execute was implemented, it would become possible
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#5 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 24 September 2011 - 11:02 PM

MMmm... might not be impossible. If you reference a script, then the reference would be obfuscated as well, so it would still point to the correct thing. You would need an "instance" for variables etc. to work though... But it's definitely worth thinking about...

What you should probably do just now, is do your own callback, then have GML "query" it, that way you could return the data or an error if it's not ready yet. It keeps everything inside your own JavaScript code....?
  • 0

#6 TGMG

TGMG

    G-java creator

  • New Member
  • 706 posts
  • Version:GM8

Posted 24 September 2011 - 11:30 PM

It is possible but a bit of a hack, just call your function like this:
gm_Ajax(verb, url, _Script_scriptname);

Change scriptname with the name of your script.

For example this code will run the script called testscript:
callback=_Script_testscript
script_execute_callback(callback);

Where script_execute_callback is simply:
script_execute_callback=function(callback) {callback();}

  • 0

#7 OMGCarlos

OMGCarlos

    GMC Member

  • GMC Member
  • 329 posts
  • Version:GM:HTML5

Posted 24 September 2011 - 11:56 PM

Mike can you expand on what you mean by an "instance" for variables? I have a RPG-Style dialogue box for a showcase I'm trying to work on, and on certain screens I need to execute different scripts. All my script ID's are stored in variables, but obviously execute_string doesn't work. This demo is what I'm trying to achieve:
http://afoobar.com/g...case/index.html
  • 0

#8 Mike.Dailly

Mike.Dailly

    Evil YoYo Games Employee

  • Administrators
  • 5277 posts
  • Version:GM:Studio

Posted 25 September 2011 - 08:55 AM

It's nothing too complicated. Whenever you execute a script, you always have an instance of an object to work with. All variables used in the script are stored in the instance, while globals are stored in a global class.

This is handled for you, but if you think about it... the only place where you're NOT calling a script from an instance, is inside the room creation code.
  • 0

#9 aiacono

aiacono

    GMC Member

  • New Member
  • 13 posts

Posted 25 September 2011 - 08:59 PM

Made a forum account that isn't just a random number, and wrote a solution here: http://gmc.yoyogames...howtopic=520277
  • 0