just to test it, remove max_enemy_count and replace it with 5 and see if that works. Maybe max_enemy_count is being changed somewhere, or not defined as 5. If you replace it with 5 and it still does it, that's weird.