PDA

View Full Version : OK, someone just tell me I'm an idiot please - ContainsKey issue



SoW Reddog
Jan-03-2014, 12:45
OK, here's the thing. I've got a dictionary "SpawnPoints", which holds two keys, "Biggin_Hill" and "Zutkerque"

So why, when I run the code below as part of OnBattleInit() do I get the following printout in the message window



SpawnPoint:Biggin_Hill
SpawnPoint:Zutkerque
Abbeville
yes
and then it stop working and when looking in the console the error is "item not found in dictionary" or somesuch. I KNOW it's not in there, it shouldn't be trying to do anything with Abbeville. I cannot see the wood for the trees, please someone put me out of my misery.



List<string> spawns = new List<string>(SpawnPoints.Keys);
foreach (string s in spawns)
{
GamePlay.gpLogServer(null, "SpawnPoint:" + s, null);
}
foreach (AiAirport ap in GamePlay.gpAirports())
{
GamePlay.gpLogServer(null, ap.Name(), null);
if(SpawnPoints.ContainsKey(ap.Name())); //Does List of SpawnBases contain this airfield?
{
GamePlay.gpLogServer(null, "yes", null);
if(SpawnPoints[ap.Name()].Item1==true)//Is airfield Active?
{
//do some stuff
}
}
}

ATAG_Colander
Jan-03-2014, 12:51
if(SpawnPoints.ContainsKey(ap.Name()));

look at the ; at the end :D



Top 10 reasons compilers must be female:

10. Picky, picky, picky.
9. They hear what you say, but not what you mean.
8. Beauty is only shell deep.
7. When you ask what's wrong, they say "nothing".
6. Can produce incorrect results with alarming speed.
5. Always turning simple statements into big productions.
4. Smalltalk is important.
3. You do the same thing for years, and suddenly it's wrong.
2. They make you take the garbage out.
1. Miss a period and they go wild

SoW Reddog
Jan-03-2014, 12:56
if(SpawnPoints.ContainsKey(ap.Name()));

look at the ; at the end :D

You're kidding . FFS
http://i.stack.imgur.com/jiFfM.jpg


Thanks Colander, would you believe that's just taken an hour to solve (or not in my case).

Dutch
Jan-03-2014, 18:12
You're an idiot.

Sorry, had to. Just had to. Sorry. :D

SoW Reddog
Jan-04-2014, 06:25
Thanks Dutch, I can sleep now and not worry anymore :D