❔ [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
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
what do you mean?
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?i want to update the reference
whenever i change/do something with my struct
so @thinker227 any ideas how to achieve it?
So update the struct stored in the class every time something in the struct updates?
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
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.
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)
why does it have to be a struct?
it can be a class
Then make it a class, then the values will be updated everywhere
As long as it's the same instance, of course
nvm, it actually must be a struct
why?
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.