On Friday, 1 July 2022 at 13:28:26 UTC, Chris Katko wrote:
...wait, does "world" not 'exist' until after the constructor
finishes? Is that's what's going on? But then why does it
'exist' when I send it directly? Is it only "registered" with
the module once this() finishes or something like that?
Yep, that's it.
moving all code in world.this() to world.initialize() and
immediately calling initialize, works fine.
````D
g.world = new g.world_t; // code would crash here
g.world.initialize(); // doesn't crash if moved here
class world
{
this(){}
void initialize(){/*...*/}
}
class elf : unit
{
this(pair _pos, atlasHandler atlas/*not used*/)
{
super(0, _pos, pair(0, 0), g.dude_bmp);
anim = new animation(1, elf_coords, g.world.atlas); //not
crashing now
}
}
````
It appears module access to a class is broken until the
constructor finishes.