Page 1 of 1

if then and or (ect)

PostPosted: Wed Jul 05, 2006 9:25 am
by madstrom
im new to c but not to seimens step 5.7 so i think im stuck in the rut of that witch is of course plc,s and not computer
i caint seem to get a if then peice of code to work
i write it
if (varx=1)
{
play sound
}
but the sound just plays no matter what varx is
ive set var1 a int
and i change its state with key down varx=1;
key up varx=0;

what am i doing wrong please anyone

PostPosted: Wed Jul 05, 2006 10:28 am
by DilloDude
To compare two values use == rather than =.

PostPosted: Wed Jul 05, 2006 10:35 am
by madstrom
have tryed that seems to play the sound anyway almost like the variable is still set at 1 im sure its something simple im doing wrong

PostPosted: Wed Jul 05, 2006 10:57 pm
by Fuzzy
When you do that, the if returns true, meaning to execute the contents of the {} brackets.

However, since you only used = and not == it sets the variable to 1, so it ALWAYS executes.

in an if statement do this

if (var == value)

not

if (var = value)

== means compare, = means assign. Its a tricky thing, and even experienced programmers do it now and then. its a good place to check when you have errors that dont crash the game.