Jump to content


Photo

gmCallback - HTML5 Extension


  • Please log in to reply
8 replies to this topic

#1 JacksonYarr

JacksonYarr

    GMC Member

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

Posted 02 August 2012 - 08:20 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:38 AM.

  • 4

#2 YellowAfterlife

YellowAfterlife

    GMC Member

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

Posted 02 August 2012 - 09:51 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

#3 JacksonYarr

JacksonYarr

    GMC Member

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

Posted 03 August 2012 - 06:22 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:12 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:14 PM.

  • 0

#5 Schalk

Schalk

    GMC Member

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

Posted 14 August 2012 - 01:31 AM

This is a great idea.
  • 0

#6 kloust

kloust

    GMC Member

  • GMC Member
  • 41 posts
  • Version:Unknown

Posted 29 August 2012 - 11:01 PM

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

#7 Dark91

Dark91

    GMC Member

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

Posted 11 September 2012 - 01:49 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:16 PM.

  • 0

#8 JacksonYarr

JacksonYarr

    GMC Member

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

Posted 14 September 2012 - 11:34 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
  • 425 posts
  • Version:GM:Studio

Posted 20 May 2013 - 12:57 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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users