godotjs / javascript

Javascript binding for godotengine
https://godotjs.github.io/
MIT License
980 stars 82 forks source link

Not an issue but a general question #123

Closed anatoli-dp closed 1 month ago

anatoli-dp commented 2 years ago

As it is i much prefer javascript over gdscript however would like to get one thing sorted before trying out this package . . . what happens if i use a custom module? I am currenty using zylan voxel module in my game and want to be able to program in javascript but am unsure if the api would also be available or is it strictly the api that godot comes with natively? Does this project use some sort of reflection allowing different modules to still be used and called upon or is this a nogo for that?

nmerget commented 1 year ago

I didn't test the voxel module, but in general, it is possible to use GDScript and JS/TS.

I have an example with a GDScript and TS file.

The important thing would be that you use new() to instantiate and call to execute the function:

import Bla from "res://scripts/gd/Bla.gd";
...
const bla: Bla = Bla.new();
bla.call("run_in_bla");

Another way would be to use a signal with some "connection" GDScript or you can try it with a auto-load sigleton

nmerget commented 1 month ago

Added an example: https://geequlim.github.io/ECMAScript/examples/use-gdscript-in-ts/