[FTC]: Top Hat coding problem

ok yet another coding problem for me.

this is my problem:

if (joystick.joy2_TopHat = 0)
    {
      servo[ServoB] = 20;
    }
    else
    {
      servo[ServoB] = 255;
    }

this won’t work, nor will

if (joy2_TopHat = 0)

i need the top hat button to activate servos, but nothing is working
contacted patrick, but it still doesn’t work…he’s studying and i don’t want to bother him anymore haha

Your problem is just an syntax error.

The sign “=” is an assignment operator where the sign “==” is the comparison operator. So you would have to do…

if(joystick.joy2_TopHat == 0)
{
code goes here
}

thanks it works

Ask me how long it took me to remember that “or” in C is really “||”. Some of us haven’t programmed in C in a L-O-N-G time. :slight_smile:

I have never programmed in C before. I picked up the basic syntax from java and I just needed to learn the functions for this year.

The syntax is amazingly similar.

The secret of software development is that structures replicate a lot across languages, but the language programmers randomly change syntax. You will eventually find yourself thinking, “OK, how do I do recursive functions in this <blank blank> language.” You know the structures are there somewhere – you just need to decipher how to make it work in THIS language. Using “&&” instead of “and,” for example, is just an arbitrary choice from the dim past. YMMV.