C
C#8mo ago
Cubic

is there any way to make something be checked for every time a field is updated or do i need to use

the property Energy is based on the field CurrentEnergy. CurrentEnergy is the one that keeps being set, and energy is only computed every now and then. any way to link this check to every update of CurrentEnergy? [this is all inside a class]
No description
7 Replies
Cubic
CubicOP8mo ago
link between the two, if necessary
No description
Buddy
Buddy8mo ago
use a setter That maybe calls an event
private string _value;
public string Value
{
get => _value;
set
{
if (value == _value) return;
_value = value;
OnValueUpdated(value);
}
}
private string _value;
public string Value
{
get => _value;
set
{
if (value == _value) return;
_value = value;
OnValueUpdated(value);
}
}
Something like that
leowest
leowest8mo ago
that is also similar to what UI frameworks do
Cubic
CubicOP8mo ago
that's definitely very useful to know about thanks 👍 honestly at the end of the day this still doesn't work because i need to add to the output string, which is only declared in certain scopes, so i wound up modifying some other properties to make this work
br4kejet
br4kejet8mo ago
You should probably check the new value of CurrentEnergy before actually updating it. Setting a value in a property getter is typically a nono In the same CurrentEnergy setter, you can then check if the new value equals the max energy, and if so, increment output by Phase3()
Cubic
CubicOP8mo ago
honestly, yeah, that's fair, and i did try changing that for a few other properties that had the same problem, but i then realised some of my code is based on the asusmption that those values are not updated until checked.... so yeah i'm probably gonna need to rework my code soon lmao for now, i'd rather have it this way than have a strange and unclear discrepancy between when to update Energy vs CurrentEnergy or something like that.
Want results from more Discord servers?
Add your server