Jump to content


Photo

gmCallback - HTML5 Extension


  • Please log in to reply
14 replies to this topic

#1 JacksonYarr

JacksonYarr

    GMC Member

  • GMC Member
  • 248 posts
  • Version:GM:Studio

Posted 02 August 2012 - 08:34 PM

gmCallback

By JacksonYarr


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).

Download - Host-A (0.35 MB) ~ View Example ~ View Help File

Update:
- gmCallback now supports arguments! The example and help file have also been updated to reflect the changes.

Edited by JacksonYarr, 14 September 2012 - 11:52 AM.

  • 8

#2 YellowAfterlife

YellowAfterlife

    GMC Member

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

Posted 02 August 2012 - 10:05 PM

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.
_.png_.gif

#3 JacksonYarr

JacksonYarr

    GMC Member

  • GMC Member
  • 248 posts
  • Version:GM:Studio

Posted 03 August 2012 - 06:36 AM

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?
  • 0

#4 idealcastle

idealcastle

    GMC Member

  • New Member
  • 4 posts
  • Version:GM:Studio

Posted 13 August 2012 - 07:26 PM

GM:Studio unable to load those type of files. -_-

Unless I'm missing something of how extensions work?

Edited by idealcastle, 13 August 2012 - 07:28 PM.

  • 0

#5 Schalk

Schalk

    GMC Member

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

Posted 14 August 2012 - 01:45 AM

This is a great idea.
  • 0

Game Maker HTML5 Extensions
Mouse Extension | HTML Extension


#6 kloust

kloust

    GMC Member

  • GMC Member
  • 41 posts
  • Version:Unknown

Posted 29 August 2012 - 11:15 PM

I agree - nice idea! I may use this in my upcoming project
  • 0

#7 Dark91

Dark91

    GMC Member

  • GMC Member
  • 27 posts
  • Version:GM:Studio

Posted 11 September 2012 - 02:03 PM

Very good!!! now im going to test this extension :-D!

edit:

work well :-D good work!

but how arguments? it can be very useful...

Edited by Dark91, 11 September 2012 - 02:30 PM.

  • 0

#8 JacksonYarr

JacksonYarr

    GMC Member

  • GMC Member
  • 248 posts
  • Version:GM:Studio

Posted 14 September 2012 - 11:48 AM

Thanks all for the feedback. :thumbsup:


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. :turned:

- JacksonYarr
  • 1

#9 alexandervrs

alexandervrs

    GMC Member

  • GMC Member
  • 745 posts
  • Version:GM:Studio

Posted 20 May 2013 - 01:11 PM

Can I somehow return back a value from a script?

 

I have a getState() GML script that returns a string to an external Javascript function but I am getting undefined.


  • 0

#10 THE_T_V1RUS

THE_T_V1RUS

    GMC Member

  • GMC Member
  • 690 posts
  • Version:GM:Studio

Posted 28 April 2014 - 01:41 PM

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!


  • 0

GM-banner-DigitDash.png

 

bannergmmentors5.png <--- Have a question? Click here to PM me


#11 Ruub

Ruub

    Finn The Human

  • GMC Member
  • 762 posts
  • Version:GM:Studio

Posted 01 May 2014 - 09:26 AM

This seems so brilliant, but I have no idea how to use it.

 

You can check resize and use custom javascript to resize your window, which might add huge benefits (in my case). Where would you even start with this?!


  • 0

#12 iceshield

iceshield

    GMC Member

  • GMC Member
  • 515 posts
  • Version:GM:Studio

Posted 10 May 2014 - 03:23 PM

This is awesome, :thumbsup:


Edited by iceshield, 25 May 2014 - 01:15 PM.

  • 0

If you put comments in your code to understand it ... then you awful at writing code.


#13 token

token

    GMC Member

  • GMC Member
  • 26 posts
  • Version:GM:Studio

Posted 11 January 2015 - 06:39 PM

Jackson, great extension! Thanks!

 

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!

PS: I use the 1.4 version, but I think it is true for 1.3 as well.


  • 0

SignatureImage.png


#14 DamonZero

DamonZero

    GMC Member

  • GMC Member
  • 21 posts
  • Version:GM:Studio

Posted 08 March 2015 - 08:57 PM

Just FYI in case anyone else needs this:

 

I needed to return a string from a gmCallback function.  I modified line 34 of gmCallback.js v1.1 

 

old line:    gmCallback[extname] = REMOVED"(function("+ args +"){"+ obFunc +"("+ gmres + args +");})");

new line:  gmCallback[extname] = REMOVED"(function("+ args +"){ return "+ obFunc +"("+ gmres + args +");})");

 

This work pretty good for me.


Edited by DamonZero, 08 March 2015 - 08:58 PM.

  • 0

#15 Sammi3

Sammi3

    GMC Member

  • GMC Member
  • 246 posts
  • Version:GM:Studio

Posted 28 August 2015 - 06:08 PM

Seems really interesting but I can't put my head around how to implement it.

 

Does it work with a javascript included file in gamemaker?

 

NEVERMIND

 

Worked it out.


Edited by Sammi3, 28 August 2015 - 06:52 PM.

  • 0