Count updating before it's supposed to
This function is called in an infinite loop. When run, the code writes to the console with the previous and current collectible counts. For example, let's say I have 2 collectibles. The code writes:
"Current TE Count = 2"
"Previous TE Count = 2"
Every time the loop executes.
When I then collect a collectible, since there is literally nowhere else in the code assigning anything to the previous count other than what I've posted, I would expect to see:
"Current TE Count = 3"
"Previous TE Count = 2"
Then the if statement would be called, updating the previous count and only then should I see:
"Current TE Count = 3"
"Previous TE Count = 3"
In reality, I never see a console write where the current and previous counts are different.
Any idea why? I'm aware this is difficult to answer without any other code but believe me when I say I have checked to see if previous count is being updated somewhere else many times.
4 Replies
If you want to monitor changes to a collection you should use ObservableCollection<T>
I'm not sure that's what I want
the issue is that I am constantly updating the data in the collection. I need to only recognize when a value changes. It seems like an observable collection can't tell the difference between an assignment of the same value and an assignment of a different value but I'll happily be wrong
this also seems like a case where that implementation is far more complex than what is required. And it still doesn't answer the question of why is the code not executing in the correct order
I'm not using any async implementation anywhere. Multithreading yes but there's only one thread ever working on this section of code
for reference
solved
is a bad idea.
it sets the arrays to be equal and for some reason... always equal. I wasn't aware this is how arrays work but sure why not