illegal else without matching if

Posted on 2006-04-24
Last Modified: 2008-01-09

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'
                              // turn it on
                              // Activate the 'light'
                        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();
                        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?
Question by:amckern
    LVL 10

    Expert Comment

    >>else ( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.

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

    LVL 84

    Accepted Solution

     if (cvar->FindVar("mat_fullbright")->GetInt() == 1){//is it on?
      //**Error here**
     }else ( cvar->FindVar("mat_fullbright")->SetValue(0));//well turn it off.
    LVL 5

    Expert Comment

    Hi  amckern.
    before else must be ';':

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

    Author Comment

    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 :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

    734 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

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now