pardon my confusion, I’m just not really understanding the How they are decoupled part. This is my 2nd course through GDTV and I just havn’t seen such usage with Events prior. So Events and how they decouple scripts from each other is a bit new to me.
I do see, now, what you mean about how if TurnSystemUI script is removed that TurnSystem will still work properly. If you had asked me to write this code out a couple weeks ago instead of using making the Event OnTurnChanged, my code probably would have looked a little more like this:
class TurnSystem
private void OnTurnChanged()
{
TurnSystemUI.UpdateTurnText();
TurnSystemUI.UpdateEnemyTurnVisual();
}
In this specific scenario, where OnTurnChanged() calls the TurnSystemUI functions directly, then yes, TurnSystem and TurnSystemUI would now become circular dependent on each other.
but with how you have it using OnTurnChanged as an Event. it prevents that circular dependency because the functions are still being held and called within the TurnSystemUI script itself.
honestly just typing all this out has helped me process and understand how Events work a little bit more, and even still I probably got it wrong but, basically to sum up my basic understanding is this:
Events give the programmer a way to make Decoupled & Indirect calling of functions outside of it’s base class. While this isn’t fool proof, and if written poorly, they could still end up with a circular dependencies, it is a method to help prevent such dependencies from occurring.