Making Character Stat variables communicate with each other?

Hello there! I’ve created some stat variables for my character. But these stat’s boundaries or values can change when other stat’s changes too. For example: my current health cannot be higher than my max health, or when my luck gets increased my crit chance has to gets increased too etc. I can make them minimum values in details section, but don’t know what to do with the other problem. Thanks in advance!
image

Hello there!

I totally understand what you’re going through. I had a similar issue in my project. For ensuring that CurrentHealth doesn’t exceed MaxHealth, you can handle this in Blueprints by creating a custom event that checks if CurrentHealth is greater than MaxHealth, and if it is, set CurrentHealth to MaxHealth.

For linking Luck and CritChance, you can create a function to update CritChance based on Luck and call this function every time Luck changes. This way, when Luck increases, you can automatically adjust CritChance accordingly.

This approach worked well for me, and I hope it helps you too!

1 Like

Thanks a lot for the answer, and also I should make an event for the luck’s change, just like the health event, right?

I’ve done something like this, and I will call this event whenever a luck changing thing happens right? Game development is HARD

Yeah spot on that should work, let me know if you run into any issues when testing it out

1 Like

a fancy way is to use objects as attributes. the objects can then bind to when their ‘parent’ attribute changes.

so Luck updates, calls an eventdispatcher, critchance is bound to that dispatcher and updates its ‘luckbonus’

this also lets each attribute have its own maxvalue and can clamp when edited.

slightly simpler is to use a struct for each attribute
(
value
maxvalue
additive bonus
multiplication bonus
)

2 Likes

I used struct before but didn’t think of it that way, seems pretty logical, I will adjust some variables like that, Thanks a lot!!

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