If else if ignoring result of first if statement?Solved

Hi,

So I have two if else if statements, virtually identical aside from a few variables changed.

Here's the first:


Here's the second:

You can see syntax highlighting links the if else if statements.

Now here's the kicker:

The first one acts as intended and will only process the else if, with the first if statement returning false.

The second one processes BOTH if statements regardless of the first statement returning true, as if the else isn't even there!

Any ideas why?!?!

So a couple possibilities:

  1. The 2nd if is somehow being globbed into the 1st else if due to lack of braces, but unlikely as C# generally only handles the first line after an if

  2. It isn't actually handling both, and is just being mistaken somehow ;)
5e13a8d5b2bc5.jpg Wulf

So a couple possibilities:

  1. The 2nd if is somehow being globbed into the 1st else if due to lack of braces, but unlikely as C# generally only handles the first line after an if

  2. It isn't actually handling both, and is just being mistaken somehow ;)

I also tried:

if (CH47NetIDs.Contains(entityNetID))
{
    Puts("Contains");
    Puts("Entity ID: " + entityNetID.ToString());
    Puts("Entity ID List: " + CH47NetIDs.ToSentence());
    CH47NetIDs.Remove(entityNetID);
}
else if (CH47DespawnAnnouncements)
{
    Puts("why");
    CreateAnnouncement(CH47DespawnAnnouncementText, CH47DespawnAnnouncementBannerColor, CH47DespawnAnnouncementTextColor);
}

 

Which outputs into console:

[GUIAnnouncements] Contains
[GUIAnnouncements] Entity ID: 81229
[GUIAnnouncements] Entity ID List: 81229
[GUIAnnouncements] why

Both if else if statements are not right next to each other.

 

However if I do:

Puts("OnEntityKill called");
if (CH47NetIDs.Contains(entityNetID))
    CH47NetIDs.Remove(entityNetID);
else if (CH47DespawnAnnouncements)
    CreateAnnouncement(CH47DespawnAnnouncementText, CH47DespawnAnnouncementBannerColor, CH47DespawnAnnouncementTextColor);

Then I get:

[GUIAnnouncements] OnEntityKill called
[GUIAnnouncements] OnEntityKill called

 

So you're right, it was being mistaken. Apparently when you shoot a Chinook down it calls OnEntityKill twice.

Sounds to me like it was triggered twice, because you remove it in the first if... so the second loop would trigger the else if.
5e13a8d5b2bc5.jpg Wulf
Sounds to me like it was triggered twice, because you remove it in the first if... so the second loop would trigger the else if.

Yeah when you shoot a Chinook down it calls OnEntityKill twice. Is that why the hook OnHelicopterKilled exists?

If .Kill is called on something, I believe it calls the hook again due to it calling that method again.
5e13a8d5b2bc5.jpg Wulf
If .Kill is called on something, I believe it calls the hook again due to it calling that method again.

Not sure I follow? I do the same thing with the patrol helicopter and it only calls OnEntityKill once.

The CH47 has an override:

See the hook being called? It also inherits the base OnKilled... which calls:


The same would apply to the Bradley APC.
5e13a8d5b2bc5.jpg Wulf
The CH47 has an override:

See the hook being called? It also inherits the base OnKilled... which calls:


The same would apply to the Bradley APC.

Ah yeah I follow you now.

What are you using to view the code of CH47Helicopter?

Using JustDecompile.
Thank you for your help!
Locked automatically