how to test a functions true

1
2
3
4
    if (check_area_free(origin.x,origin.y+1) == true)
    {
        vspeed+=.1;
    }


Im not to sure if Im writing this properly or not.

I have a function check_area_free and it returns true or false.
now the code above is supposed to do the code in the brackets, if the function returns true?
is this the correct way of writing it?
Yes, that is correct. Although those are {braces}, not [brackets] ;P
closed account (zb0S216C)
GPP wrote:
now the code above is supposed to do the code in the brackets, if the function returns true?

Yes. If the condition of the if statement evaluates to true, the statements within the braces are executed. If false, the statements aren't executed.

You can cut down the size of the if statement. For example:

1
2
3
if( check_area_free( origin.x,origin.y + 1 ) ) // If true...

if( !check_area_free( origin.x,origin.y + 1 ) ) // If false... 

Wazzak
Last edited on
Thanks Guys, and I had a feeling there was a way to shorten it.
Topic archived. No new replies allowed.