• 0

[C++] Counter Madness


Question

Hi guys, this is driving me absolutely nuts! why on earth is this not working!!!!

int m_ntotalSAS = 0;
	int iCounter2 = 0;
	//reset the total number of sas
	m_ntotalSAS = 0;
	//work out how many SAS their are in total
for (int i = 1; i <= 32; i++ )
	{
		CHL2MP_Player *plr = (CHL2MP_Player*) UTIL_PlayerByIndex( i );

		if ( plr )
		{
			if ( plr->GetTeamNumber() == 3){
	m_ntotalSAS++; 
			}
		}
	} 




//check to see if the entity that we hit is a player
CBaseEntity *pPlayer = dynamic_cast<CBaseEntity *>(pOther);

iCounter2 = 0;
int iSAScounter;
iSAScounter = 0;
int iArraypos;
iArraypos = 0;

if(pPlayer){
//our person is a player

	if ( pPlayer->GetTeamNumber() == 3){
	//search through our array to see if his handle is already in their, if not add it

	//search

	for (int i = 0; i <= 32; i++ )
	{

		if ( m_nSAS[ i ] == pPlayer->GetServerHandle()){
		//we found our player in teh array dont bother diong anythuing
iCounter2++;
		}
		if (m_nSAS[ i ] == NULL){
		//let us know the position of a blank slot plz
iArraypos = i;
		}else{
		iSAScounter++;
		}

	} 


	}
}

in the first FOR loop, the m_ntotalSAS++ gets called once, which should increment that integer by 1?

instead i get some horrible number that changes every single time to something completely random. whats going on??

the same thing is happening with iSAScounter++; and iCounter2++;

they are all returning horrible values?! and i havent got a clue why its doing that. whats going wrong?

-Alex

Link to comment
https://www.neowin.net/forum/topic/636135-c-counter-madness/
Share on other sites

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.