Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Studio Chat / [HTML5] Send values from Javascript to AGK

Author
Message
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 4th Sep 2020 22:18
I came across a post https://forum.thegamecreators.com/thread/221260 that describes a method using the message() function and some custom javascript to send messages from AppGameKit to javascript running on a page. The author also talks about doing the reverse using "async http calls" . Does anyone have any idea how this can be done? It would be great as we can use third party javascript libs that can communicate with exported html5 apps.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th Sep 2020 05:55 Edited at: 5th Sep 2020 05:57
thanks for bringing that guide to light. i must have missed it the first time around and it's got me looking at JS for the first time and as potential solution for Clipboard functionality in HTML.

i've followed xCept's guide and have their example running fine on itch.io so i'm hopeful

not very helpful re: your inquiry but i've seen reference to async http calls while skimming through some JS pages since.

i'm ignorant in all things JavaScript but i'll be looking taking a deeper look at it all. meanwhile, which libraries do you think we could benefit from? anything in particular?
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 5th Sep 2020 09:25 Edited at: 5th Sep 2020 09:25
Thanks for the quick reply. I want to use Tone.js to make a mod tracker that runs from the browser. As it stands, i can do this now and for the most part it will work but i need feedback from Tone.js to update things in the AppGameKit app.

https://tonejs.github.io/
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 7th Sep 2020 09:59
I ended up switching to Godot for this project. I hope the devs will add this feature in the near future.
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 8th Sep 2020 12:31
Godot just isn't cutting it for me. Please please, can anyone send me in the right direction?
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 8th Sep 2020 17:41 Edited at: 8th Sep 2020 17:43
You may want to consider the cookies since this is for your HTML5 builds.

Search the docs for the shared variables that are now available if you are using the latest build of AGK...

type "Shared" in the search box for the online docs.

You will need to explore how to access and write to those cookies with JavaScript, but it should be doable.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
gosukiwi
AGK Tool Maker
3
Years of Service
User Offline
Joined: 24th May 2020
Location: Argentina
Posted: 9th Sep 2020 04:45 Edited at: 9th Sep 2020 04:46
Oh my god, the way he gets to call JavaScript functions is a total insecure and slow hack. Use at your own risk.

Apparently, when running Tier 1 in the browser, the `Message` function will call `window.alert`. So what he does is hijacking that function and calling`eval` to run some function. Using eval is rarely a good idea. Especially in that case, he could have just done `window[myFunctionNameAsAString](params)`.

I don't know how he planned on doing the opposite though, given that all of AppGameKit's code gets compiled with emscripten to asm.js, which is basically bytecode, so you can't just access the function names and stuff. I think what he means by using HTTP requests is to have the JavaScript code send HTTP requests to some server written in Tier 1.

Not sure if AppGameKit supports WebSockets but if they do, it would surely be much better for communicating than HTTP requests. If you really want to use JavaScript though, by far the best would be just to use something like Phaser or Pixi.js.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Sep 2020 07:39 Edited at: 9th Sep 2020 07:53
it might be too slow to take advantage of Tone.js and an obvious hack but OrangeTEK (and i) are obviously grasping at straws to bring functionality to AppGameKit that it doesn't offer natively.

where Tone.js is "a Web Audio framework for creating interactive music in the browser", i would assume it needs to "listen" to a stream of "real time" audio so i'm not sure cookies would help with the read/write times involved (and it seems it would jackhammer our hard drives while "streaming" the audio data as cookies?) ?

AGK does, apparently, support sockets but in HTML it "uses a WebSocket which sends an HTTP style header and requires an HTTP style response to connect" which you advise against?

regardless, can you (or anyone) provide some example of (or more-direct guidance to) AppGameKit interaction with Tone.js (or the Clipboard in HTML) ?

add: i just ran a forum search and found this thread: How to get and receive messages from a websocket server, which may be helpful?
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 9th Sep 2020 16:23 Edited at: 9th Sep 2020 16:24
So, i understand that using the message() hack to communicate with raw javascript on the same page is not ideal in terms of performance or security. Godot, Defold and a few others use it too. As for getting values from Tone.js back in to AGK's asm.js, these values will be volume levels and anything related to gui changes like flashing lights, etc. It wont be a huge stream of data flowing so shared variables may be doable. Shared variables may be a way to do both directions, ill have to experiment. Thanks guys for the heads up.
OrangeTEK
4
Years of Service
User Offline
Joined: 7th Aug 2019
Location:
Posted: 9th Sep 2020 17:07
Shared variables work! They also work in both directions! Thanks Conjured Entertainment. Ill have to do some proper testing to be sure this is viable. We can also take advantage of this to transfer data between multiple agk apps running in different tabs in the browser.
Conjured Entertainment
AGK Developer
18
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 9th Sep 2020 17:09 Edited at: 9th Sep 2020 17:32
Quote: "Oh my god, the way he gets to call JavaScript functions is a total insecure and slow hack. Use at your own risk.

Apparently, when running Tier 1 in the browser, the `Message` function will call `window.alert`. So what he does is hijacking that function and calling`eval` to run some function. "

Yeah, I thought of the XSS attacks when seeing that , because some people hijack the error messages to run scripts.

Quote: "where Tone.js is "a Web Audio framework for creating interactive music in the browser", i would assume it needs to "listen" to a stream of "real time" audio so i'm not sure cookies would help with the read/write times involved (and it seems it would jackhammer our hard drives while "streaming" the audio data as cookies?) ?
"

My bad.

I missed all that, and I did see the libs part of the original post after I posted, and thought I may have given bad advice.

My mind was still focused on the thread title and was thinking simple values when I posted my suggestion.

I was not even familiar with Tone.js but after a little search.. Tone.js is really cool.

I may have to play around with those myself at some point.

Quote: "Shared variables work! They also work in both directions! Thanks Conjured Entertainment. Ill have to do some proper testing to be sure this is viable. We can also take advantage of this to transfer data between multiple agk apps running in different tabs in the browser."

AWESOME!

Glad I could help, and yeah those shared variables are just for that... sharing between multiple apps running, and I was pleasantly surprised when I ran a few of my first tests for those.

Of course, I was not testing for Tone.js , but I was seeing instant changes in one window when I made them in another, and they definitely served the purpose I was testing for.

Still have some security issues with cookies of course, but I was planning on proprietary encryption/decryption of my data being passed.

I look forward to seeing what you can come up with.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 9th Sep 2020 18:22 Edited at: 9th Sep 2020 18:25
that's good news, OrangeTEK.

i don't know why i searched "Tunes.JS" last night but it delivered a nifty Tone.JS-related video (https://www.youtube.com/watch?v=xBQef0fs-_Q) that helped me understand JS a bit, as well (near-no experience there, otherwise).

the author kinda "raced through it" which i found effective while a lot of vids "drag on" and lose my interest.

i usually scold google for getting inside my mind, but it worked out this time, so...
[My Itch.io Home] | [#LowRezJamAGK2020]
[AGK Resource Directory] | [TGC @ GitHub]
[CODE lang=AGK] Your Code Here [/CODE] | [VIDEO=youtube] VideoID [/VIDEO]

Login to post a reply

Server time is: 2024-03-29 12:45:08
Your offset time is: 2024-03-29 12:45:08