I have a struct holding condition informations.
private struct hintStructure
{
public string id;
public float value;
public bool alreadyWarned;
}
private List<hintStructure> hints;
Whenever my program changes a value, an event is sent and the condition list is checked wether that element meets a condition.
public void EventListener (string id)
{
CheckHints(id); //id of the updated element
}
private void CheckHints(string _id)
{
foreach (hintStructure _h in hints)
if (_h.id == _id) CheckValue(_h);
}
private void CheckValue(hintStructure _h)
{
float _f = GetValue(_h.id);
if (_f < _h.value)
{
ActivateHint(_h);
_h.alreadyWarned = true;
}
else
_h.alreadyWarned = false;
}
private void ActivateHint(hintStructure _h)
{
if(_h.alreadyWarned == false)
ShowPopup();
}
ShowPopup()
should only be called, when it wasn't already shown for that specific element (indicated by bool alreadyWarned
). Problem is: It's always shown. It seems like the line _h.alreadyWarned = true;
is called, but the value isn't stored (I checked if it gets called, it does).
I assumed the foreach
might be the problem (since it was buggy some years ago), but it doesn't work with a for()
structure either.
My last guess is an addressing issue, typical problem in C++:
CheckValue(h); vs. CheckValue(&h);
But if I'm correct with this guess - how can I solve this?