else if mystery

Hi; I am new here and do not understand the result I get from this part of code I changed in a game. I am not really great in C++ and appreciate any explanation.

Here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
if (pVertex1->elevation < (Terrain::waterElevation - MapData::shallowDepth))
terrainType1RGB = land->terrainTextures->getTextureTypeRGB(0); 

else if ((pVertex1->elevation < Terrain::waterElevation) && (MapData::shallowDepth < 197))
terrainType1RGB = 0x002e7599;
			

else if ((pVertex1->elevation < Terrain::waterElevation) && (MapData::shallowDepth = 197))
terrainType1RGB = 0x00bab87d; 
			
else if ((pVertex1->elevation < Terrain::waterElevation) && (MapData::shallowDepth = 198))
terrainType1RGB = 0x00544533; 
			
else if ((pVertex1->elevation < Terrain::waterElevation) && (MapData::shallowDepth = 199))
terrainType1RGB = 0x007c7666;
			
			else if ((pVertex1->elevation < Terrain::waterElevation) && (MapData::shallowDepth = 200))
			terrainType1RGB = 0x00581808; 
			
else if (isCementType(pVertex1->terrainType))
terrainType1RGB = land->terrainTextures->getTextureTypeRGB(pVertex1->terrainType);



What does not work as intended is the section for Terrain::waterelevation and the additional condition for shallowDepth. The code compiles and the game uses it without error message but it does not differentiates between 197,198,199.
It only differentiates between <197 and 200 and not only ignores the other secection options but modifies the value to the first 197.

For me this is am ystery and I try to find out if there is something wrong with that part of the code or if the issue is created in other parts of a much,much larger code. I may not understand the restrictions of using else if.

I could not compile with a select..case structure because such variables can not be used in it.
= is assignment.
== is comparison.
Stupid me ! I should have known.

This fixed it and I learned something.

Thanks a bunch
Topic archived. No new replies allowed.