Log in

View Full Version : [FTC]: Top Hat coding problem


nate15810
22-01-2009, 16:53
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

ttldomination
22-01-2009, 17:23
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
}

nate15810
22-01-2009, 18:03
thanks it works

Rick TYler
23-01-2009, 18:20
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. :)

ttldomination
23-01-2009, 19:47
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.

Rick TYler
23-01-2009, 22:33
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.