Thread: Null exception
View Single Post
  #4  
Old 03-19-2012, 04:27 AM
salmo salmo is offline
Approved Member
 
Join Date: Mar 2011
Posts: 632
Default

SmokyNZ, I concur with you that there is something screwy with the actors that gives rise to null exceptions. I'm unsure what the cause is, but here's a code snippet from a script I'm working on. The CheckActors routine was working & keys.Count was returning the number of actor keys, then all of a sudden, it failed & now persistently returns zero even though there are actors in the mission.

Code:
public class Mission : AMission
{
private Dictionary<String, AiActor> allActors = new Dictionary<String, AiActor>();

    public override void OnPlaceEnter(Player player, AiActor actor, int placeIndex)
    {
CheckActors();
}

public void CheckActors()
{
        List<string> keys = new List<string>(allActors.Keys);
        sendChatMessageTo(-1, "Keys count=" + keys.Count.ToString(), null);
       // .......
    }

    private void sendChatMessageTo(int army, string msg, object[] parms)
    {   // send a chat message to all players in specified army (1=red; 2=blue)
        List<Player> Players = new List<Player>();
        // on Dedi the server:
        if (GamePlay.gpPlayer() != null)
        {
            if (GamePlay.gpPlayer().Army() == army || army == -1)
                Players.Add(GamePlay.gpPlayer());
        } //rest of the crowd
        if (GamePlay.gpRemotePlayers() != null || GamePlay.gpRemotePlayers().Length > 0)
        {
            foreach (Player p in GamePlay.gpRemotePlayers())
            {
                if (p.Army() == army || army == -1)
                    Players.Add(p);
            }
        }
        if (Players != null && Players.Count > 0)
            GamePlay.gpLogServer(Players.ToArray(), msg, parms);
    }
}
__________________
When one engine fails on a two engine bomber, you will always have enough power left to get to the scene of the crash.

Get the latest COD Team Fusion patch info HERE

Last edited by salmo; 03-19-2012 at 04:31 AM.
Reply With Quote