Really confused by what triggers stat re-calculation

Hi there,

In these lectures, if I understood well, the stats (damage or max health) are re-calculated every time we need them. For instance, every time we need to get the maxHealth (for printing on the UI), we execute a call to the getStat function, right? The same thing is happening when we need to apply damage?
I can’t really record because I chose a different way to do stat recalculation.
I went the “event way”, meaning that I subscribe to every possible event that would impact the stats, and then I recalculate -and cache- the stat value.
For example, when we level up, an event triggers and updates all the stats.
When we equip a weapon, we have an event that updates the weapon, why isn’t it that we also add, in the UpdateWeapon method (of fighter script) a call to the UpdateDamage method?

I mean: is generally recalculating stats every time we need them a better way than recalculating stats when an event (that could impact the stat) occurs?
What can help us decide which is the best implementation: recalculating the stat every time or only when an event triggers? On what basis can we chose one way or another or writing our code?
I am also wondering which way is more performant?

I feel like I missed something…
Thank you!

No, it is actually better to use an event-driven model. Over the course series, we dive deeper into event driven coding, but we don’t explicitly go back and change what was done in earlier sections (like the HUD UI, which is just BEGGING for an event driven solution!). We leave that challenge up to you, and it sounds like you’ve already accepted and aced the challenge.

In fact, in all of my personal UI code, there isn’t a single Update loop in any of them.

It’s a tough line to draw. While this is billed as an intermediate course, we aimed to have the starting point be students who understood how to navigate the Editor and do the core C# things. A startlingly large number of students jumped right into this course and that meant that in the early lessons, we had to build up knowledge. By the end of the Core Combat course, the Observer pattern will have been introduced and folks should have a good idea how to implement it in earlier sections. Introducing it too early would have been a distraction from teaching more basic concepts.

Hello Brian,

Thank you!
Glad to hear that I’m on the righteous path of knowledge.
I’ll keep on following the lectures… and you’ll probably hear from me again soon!
Anyway, thanks for the enlightening answer (which is even more appreciated on Christmas holydays)!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms