Re: class that is initialized becomes null when outside of function

2018-07-09 Thread Flaze07 via Digitalmars-d-learn
On Monday, 9 July 2018 at 09:38:30 UTC, ag0aep6g wrote: The `win` you're creating in `init` is a function-local variable. It ceases to exist when `init` returns. It's not `this.win`. In `run`, you're accessing `this.win`. It's still null because you never assigned anything there. So change

Re: class that is initialized becomes null when outside of function

2018-07-09 Thread ag0aep6g via Digitalmars-d-learn
On 07/09/2018 11:18 AM, Flaze07 wrote: class Game { [...]     RenderWindow win; [...]     void init()     { [...]     auto win = new RenderWindow( VideoMode( 600, 600 ), "snake" ); [...]     }     void run()     { [...]     writeln( win is null ); [...]     } } the p

Re: class that is initialized becomes null when outside of function

2018-07-09 Thread Flaze07 via Digitalmars-d-learn
On Monday, 9 July 2018 at 09:18:50 UTC, Flaze07 wrote: I am using DSFML module game; [...] oh, and I forgot, I had Game myGame; static this() { myGame = new Game; } below the Game class

class that is initialized becomes null when outside of function

2018-07-09 Thread Flaze07 via Digitalmars-d-learn
I am using DSFML module game; import core.time; import std.stdio: writeln; import dsfml.graphics; import dsfgui.button; import apple; import snake; class Game { private: enum State { menu, playing } State state; Font font; Button playBtn; Snake snake; Apple apple;