C
C#2y ago
Theos

❔ [Unsolved] Call a function whenever I change variable in a struct

Hey, so I have a hue struct public Statistics stats; with many functions and variables in it. I need to do stats = stats whenever I call a function inside stats or just change a variable in it. How can I do this?
14 Replies
Thinker
Thinker2y ago
Are the "variables" in the struct fields or properties? or wait, nvm You probably want a class instead of a struct Because it sounds like you want more reference semantics rather than value ones
Theos
Theos2y ago
what do you mean?
Thinker
Thinker2y ago
You have a Stats stored somewhere in a class, and every time you call or edit something inside the struct you want to update it everywhere?
Theos
Theos2y ago
i want to update the reference whenever i change/do something with my struct so @thinker227 any ideas how to achieve it?
Thinker
Thinker2y ago
So update the struct stored in the class every time something in the struct updates?
Theos
Theos2y ago
Yeah Whenever I call a function in that struct Or directly change the variable Like stats.hp = 5 All functions change at least one variable
Thinker
Thinker2y ago
But this struct is already stored in a class? If you're calling the methods on that specific instance, then you shouldn't need to update the instance.
Theos
Theos2y ago
well, I need to update the instance/reference I could go into more details but it's not really that important (I am using a networking library and we are trying to fix something)
ero
ero2y ago
why does it have to be a struct?
Theos
Theos2y ago
it can be a class
ero
ero2y ago
Then make it a class, then the values will be updated everywhere As long as it's the same instance, of course
Theos
Theos2y ago
nvm, it actually must be a struct
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server