Skip to content

Instantly share code, notes, and snippets.

@nonunknown
Last active September 23, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nonunknown/ed92069b9282e214d8bad3cce0511266 to your computer and use it in GitHub Desktop.
Save nonunknown/ed92069b9282e214d8bad3cce0511266 to your computer and use it in GitHub Desktop.
Godot & Javascript - How to deal with async results

Godot & Javascript - How to deal with async results

My task: Get a function of godot called by Javascript! The Problem: godot's javascript class, doesnt support functions which doesnt return the value immediately

So, this is a step by step of what I've done, I'm using Node.js with a godot application which needs to get data from that node.js server!

First Step

I've added to the export project header include for HTML, 2 script tags: one for the ajax, other for my custom file.js which will be alongside the exported godot files:

image

Second Step

Create the files.js file:

image

PS: Remember that files.js must be in the same path as .pck when you export the project

Third Step

Now we are going to tell godot how to deal with all this shit!

image

The Final Result:

image

Those logs are from godot, and not javascript nor node.js

PS: this is the code in node.js called by ajax: image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment