Hello everyone,
I am encountering an amazingly frustrating problem that just has me ripping my hair out. It's bit complex so I will try to summarize.
I have a large number of instances of the same EnemyMonster.
The EnemyMonster has two instance variables important to this:
1) Behavior - an int 0, 1 or 2
2) searching - a bool
I also have a global variable called "whoSearching"
The behaviors are as follows
0 - Idle
1 - Attacking
2 - Searching for target
I am trying to track how many EnemyMonsters have Behavior set to 2, searching.
All EnemyMonsters start with Behavior 0 and searching as False, and whoSearching starts at 0.
When an EnemyMonster is set to Behavior 2 and its searching is False, I add 1 to whoSearching and set its searching to True so this will only run once for each EnemyMonster set to Behavior 2.
When an EnemyMonster is set to Behavior 0 or 1 and its searching is True, I subtract 1 from whoSearching and set its searching to False.
Being set to Behavior 2 is the only way to end up with searching as True on any given EnemyMonster, so it must pass through this state before being set to Behavior 1 or 0 has any effect on that instances searching bool or the whoSearching global.
And yet I still get some instances ending up with searching as True without ever being set to Behavior 2 causing my count to be way off.
I really do not understand why this is happening, it seems like such a simple concept but I just cannot seem to figure it out.
If anyone has any ideas I would really appreciate it.
dl.dropbox.com/u/61677895/Wastes.caproj
And here is the .caproj for anyone who wants to check out the nitty-gritty details of my script, maybe I'm making a different mistake somewhere and it's effecting this.
Thanks a lot for any help :)