I have the following Haxe class, ModList.hx
class ModList
{
public function new ()
{
trace("Mod List Constructor");
}
public function getDataPacks(): Array<String>
{
trace ("getDataPacks was called");
return new DataPacks().getDataPacks();
}
static public function main ()
{
trace("Hello from Mod List.");
}
}
I’m targeting this to JavaScript because I want to load some content in another Haxe project without using Haxelib and thus requiring a recompile. Instead, I will use a JS file that I load as extern. The JS file is generated from the Haxe project that I can recompile (all this is for a moddable game and modders shouldn’t have to rely on anybody recompiling the engine).
So, this is my Extern class for the class above, also called ModList.hx but in the package externs.modlist.
package externs.modlist;
extern class ModList
{
public function new();
public function getDataPacks(): Array<String>;
}
Both these files reside in the first Haxe project, the “mod”, and the extern is loaded in a second Haxe project, a game engine.
Now, when I load the page in the game engine, the JavaScript-targeted Haxe project where I’m using this extern, the main method executes because I get “Hello from Mod List”, so everything seems to be in working order. (yes, I included the JS in the HTML page).
However, when I try to call getDataPacks, I get a JS error directly on the call, no stack trace, saying “externs is not defined”.
Note that “externs” is the first word in the package name. I tried adding another name in the package, for example “john.externs.modlist”. It then says john is not defined.
Any ideas?