Open GeTechG opened 15 hours ago
This situation hasn't been considered yet. I'll handle it right away.
After some investigations, the assertion failure in is_valid()
should have been fixed in a recent commit. Please try the latest commit on the main branch.
By the way, Global
is unnecessary for TS/JS because JS supports a classical singleton pattern.
export class MyGlobals {
private static _inst: MyGlobals;
static get instance() {
if (!MyGlobals._inst) MyGlobals._inst = new MyGlobals();
return MyGlobals._inst;
}
health = 0;
}
Or, just simpily:
export class AnotherGlobal {
static readonly instance = new AnotherGlobal();
value = 0;
}
If you still want an autoload global Node
like in gdscript
originally. You could write it in this way:
// `default` is needed in this way to comply the rule how GodotJSScript find it
export default class MyGlobals extends Node {
private static _inst: MyGlobals;
static get instance() {
return MyGlobals._inst;
}
health = 0;
_ready() {
MyGlobals._inst = this;
}
}
And access it in the way like MyGlobals.instance.health = 1
. It's very similar to C# as the docs mentioned here.
The error appears when you open a project with autoload already added.
The error occurs when opening a project with already added autoloader. P.s I will add to autoload via plugin