Noel Berry

@noelfb
4.8K Followers
159 Following
525 Posts
sometimes, when i'm in the right mood, i make video games and art. created Celeste with friends, making new games with more friends. he/him
websitehttps://noelberry.ca
exokhttps://exok.com
one of the areas in our game, City of None
@PsySal I played through it a few years ago and totally agree! It was really well done
@eniko I did this for my website. It's just like 400 lines of C# code lol
@PingZing all the actual file io stuff is done way beforehand, but the room/object creation just happens as you scroll. Which so far is fine but could have problems, we'll see!
Experimenting with the idea of running save files on the title screen for very smooth game-loading ...
@nickzoic hah, nice. I've never played it, maybe I'll have to check out out
@PanNindyk Thanks! No release date yet, and no announced platforms yet. Definitely, at the minimum, Linux/Mac/Windows. We'll definitely share more in the coming weeks/months as it comes together!
I guess the "correct" thing to do is just not let instances hold a reference to their owner... but when I'm working on small projects it's often way, way simpler to be able to do that and I don't care about perfect data/control flow. I just want my objects created fully by the constructor!

You can create a pattern where child implementations just aren't supposed to do anything until an "OnAdded" is called, but that messes up readonly members and also makes it so they need to "cache" constructor arguments to be used later.

In C++ you could get around this with templates (pseudo code, can't remember syntax)

void Add<T>(constructor params) => children.Add(new T(this, constructor params));

and it wouldn't compile if you mess up the expected parameters. I kind of want that in C#.

I frequently have a design problem in C# where I want to instantiate objects with their data complete, but they also need to reference their owner for ease-of-use. But then the pattern ends up being ugly, like:

UI.Add(new Button(UI, "Confirm"));

Where that first argument is redundant + error-prone.

You can delay the assignment, so the Add method assigns the owner (ex. itemBeingAdded.UI = this) but then the child doesn't have the owner until after its constructor.