Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to call GDScript code from JavaScript in HTML5 exports #286

Closed
davthedev opened this issue Dec 5, 2019 · 4 comments
Closed

Comments

@davthedev
Copy link

Describe the project you are working on:
Integrating a technical demo (minimal 2D game) with the AirConsole (airconsole.com) service to see how feasible it is to bridge a Godot game with it. The service already supports Unity and Construct as well as a raw Javascript API.
AirConsole is an online, local multiplayer gaming platform where the actual game runs in a web browser and players use their smartphones as gamepads to control the game. Gamepad-to-game communication goes over Internet and is totally managed by the service. A simple system of pairing codes allows players to quickly join without the need to install anything on their phones.
The transmission of "key presses" from players' smartphones goes through their system and arrives to the game through a JavaScript API.

Describe the problem or limitation you are having in your project:

I cannot directly call functions or events from the JavaScript world to the Godot HTML5 game.
The opposite (Godot to JavaScript function call) is possible by calling the appropriate GDScript singleton.

According to some posts, there is a hacky way to overcome this by polling JS variable changes & reacting on it. But this limits the events possibility to the game loop framerate (60fps).
In the AirConsole paradigm, player input arrives through the JavaScript API. It would be better to process it in real time rather than waiting for the next game loop iteration.

Describe how this feature / enhancement will help you overcome this problem or limitation:

I can pass input from the controllers to the game in near-realtime, and not use the hacky polling solution that limits the input framerate to 60fps.

Show a mock up screenshots/video or a flow diagram explaining how your proposal will work:

Principle is simple:

  • JS code calls the API function
  • Callback is received in the GDScript code, like an event (not tied to game loop iteration) and runs whatever code is desired

Describe implementation detail for your proposal (in code), if possible:

Exposing an API that a JS can function can call, triggering a GDScript function call.

If this enhancement will not be used often, can it be worked around with a few lines of script?:

There is the polling possibility explained above. But requires overhead and limits input framerate.

Is there a reason why this should be core and not an add-on in the asset library?:

Can such integration of API be done using an add-on? It looks like a core communication principle.

@DleanJeans
Copy link

DleanJeans commented Dec 7, 2019

Hey, I also made a AirConsole game with Godot like a year ago. My implementation was also polling + saving/converting return values.

I'll open source when I got some free time in case you run into any problems.

https://github.com/DleanJeans/godot-airconsole

@Calinou Calinou changed the title Add JavaScript-to-Godot function call possibility in HTML5 exports Add the ability to call GDScript code from JavaScript in HTML5 exports Jun 19, 2020
@Thaina
Copy link

Thaina commented Sep 12, 2020

Is this also include C# mono. Or it would need separated issue. Or are there possible workaround in C# side?

@bend-n
Copy link

bend-n commented Sep 30, 2022

This exists now, can this be closed?

@Faless
Copy link

Faless commented Sep 30, 2022

Yes, thanks!

@Faless Faless closed this as completed Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants