if then and or (ect)

Talk about making games.

if then and or (ect)

Postby madstrom » Wed Jul 05, 2006 9:25 am

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
madstrom
 
Posts: 8
Joined: Sun Jun 25, 2006 12:48 pm
Score: 0 Give a positive score

Postby DilloDude » Wed Jul 05, 2006 10:28 am

To compare two values use == rather than =.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby madstrom » Wed Jul 05, 2006 10:35 am

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
madstrom
 
Posts: 8
Joined: Sun Jun 25, 2006 12:48 pm
Score: 0 Give a positive score

Postby Fuzzy » Wed Jul 05, 2006 10:57 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest

cron