API
All of Godot's APIs are defined within the godot
namespace.
No API names have been renamed or changed, so you shouldn't need to change your habits.
GDScript | JavaScript |
---|---|
null | null |
int | number |
float | number |
String | string |
Array | Array |
Dictionary | Object |
NodePath | string |
Object | godot.Object |
Resource | godot.Resource |
Vector2 | godot.Vector2 |
Color | godot.Color |
sin(v) | godot.sin(v) |
print(v) | godot.print(v) |
PI | godot.PI |
Color.black | godot.Color.black |
Control.CursorShape | godot.Control.CursorShape |
Label.Align.ALIGN_LEFT | godot.Label.Align.ALIGN_LEFT |
API specification:
- Keys of Dictionary are converted to String in JavaScript
- Signals are defined as constants to their classes
Additional functions
godot.register_signal(cls, signal_name)
to register signalsgodot.register_property(cls, name, default_value)
to define and export propertiesgodot.register_class(cls, name)
to register named class manuallygodot.set_script_tooled(cls, tooled)
to settooled
of the classgodot.set_script_icon(cls, path)
to set icon of the classgodot.get_type(val)
Returns the internal type of the givenVariant
object, using thegodot.TYPE_*
godot.yield(target, signal)
Returns a Promise which will be resolved when the signal emittedrequestAnimationFrame(callback)
registers a callback function to be called every frame, returns a request ID.cancelAnimationFrame(request_id)
to cancel a previously scheduled frame requestrequire(module_id)
to load a CommonJS module or load a resource file$
is the alias ofNode.get_node
Using signals
Allow passing functions for godot.Object.connect
, godot.Object.disconnect
, and godot.Object.is_connected
:
this.panel.connect(godot.Control.resized, (size) => {
console.log("The size of the panel changed to:", size);
});
Using await
to wait for signals
await godot.yield(
this.get_tree().create_timer(1),
godot.SceneTreeTimer.timeout
);
console.log("After one second to show");
Preload resources with ECMAScript import statement
Multi-threading
Multi-threading with minimal Worker API (This is an experimental feature)
Start a new thread with Worker:
const worker = new Worker("worker.js"); // Run worker.js in a new thread context
worker.postMessage({ type: "load_dlc", value: "dlc01.pck" });
worker.onmessage = function (msg) {
console.log("[MainThread] received message from worker thread:", msg);
};
Transfer value in different thread context with godot.abandon_value
and godot.adopt_value
: