?
Solved

illegal else without matching if

Posted on 2006-04-24
4
Medium Priority
?
460 Views
Last Modified: 2008-01-09
Hi

I have a small problem --- illegal else without matching if --- this is part of --- if( pPlayer->IsSprinting() )




//-----------------------------------------------------------------------------
// CalcTotalAimModifier
//
// Calc the aim penalty scale factor based on the current
// player equipment and movement state
//-----------------------------------------------------------------------------
float CNDBaseBulletWeapon::CalcTotalAimModifier()
{
      CNDPlayer *pPlayer = ToNDPlayer( GetOwner() );
      if (!pPlayer)
            return 1.0f;

      // reset
      float fTotalAimModifier = 1.0f;

      const Vector & vecSpeed = pPlayer->GetLocalVelocity();
      #define SPEED_TOLERANCE 0.1f

      int flags = pPlayer->GetFlags();
      if( flags & FL_ONGROUND )
      {
            if( flags & FL_DUCKING )
                  fTotalAimModifier *= GetAimModifierCrouched();

            // Is player currently in motion?
            if( abs(vecSpeed.x) > SPEED_TOLERANCE ||
                  abs(vecSpeed.y) > SPEED_TOLERANCE ||
                  abs(vecSpeed.z) > SPEED_TOLERANCE )
            {
                  if( pPlayer->IsSprinting() )
                  {      
                        static bool bDisplayed = false;
                        
                        if( bDisplayed )
                        {
                              // turn it off
                              // Deactivate the 'light'
                              cvar->FindVar("mat_fullbright")->SetValue(0);
                        }
                        else
                        {
                              // turn it on
                              // Activate the 'light'
                              cvar->FindVar("mat_fullbright")->SetValue(1);
                        }
                        
                        bDisplayed = !bDisplayed;
                        
                        //check if the gun is down or not
                        if (cvar->FindVar("mat_fullbright")->GetInt() == 1)//is it on?
//**Error here**      else ( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.

                  }
                        //fTotalAimModifier *= GetAimModifierSprinting();
                  else if( pPlayer->IsWalking() )
                        fTotalAimModifier *= GetAimModifierWalking();
                  else
                        fTotalAimModifier *= GetAimModifierRunning();
            }
      }
      else // player's jumping or in the air
      {
            fTotalAimModifier *= GetAimModifierJumping();
      }

      return fTotalAimModifier;
}









This works by its self


if (cvar->FindVar("mat_fullbright")->GetInt() == 1)//is it on?
      DevMsg("World is bright!\n");
else( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.
      DevMsg("End Of do da\n");




What am I doing wrong?
0
Comment
Question by:amckern
4 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 16531692
>>else ( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.

There are extra parenthesis here. No '(' required after else and no ')' before ;

HTH
Amit
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 16531744
 if (cvar->FindVar("mat_fullbright")->GetInt() == 1){//is it on?
  //**Error here**
 }else ( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.
0
 
LVL 5

Expert Comment

by:B1-66ER
ID: 16531751
Hi  amckern.
before else must be ';':

if (cvar->FindVar("mat_fullbright")->GetInt() == 1) ; else ( cvar->FindVar("mat_fullbright")->SetValue(0));
0
 
LVL 2

Author Comment

by:amckern
ID: 16531777
Thank you to you both, i made the accepted answer at the first one that worked - sorry that you got no points B1 - but i can see how your answer would have worked now :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question