PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

c++ language problems...

I'm still a little new to evc++,

and I thought the following code would work? draw_object return a bool, as is "d"


Code:

d = draw_object(sx+dirx,sy+diry) || draw_object(sx,sy);
//update screen
if (d)
{
update_screen();
//wait a little more....
wait_msec(40);
}


but instead I had to:

Code:


d = draw_object(sx+dirx,sy+diry);
if (d) draw_object(sx,sy); else d = draw_object(sx,sy);
//update screen
if (d)
{
update_screen();
//wait a little more....
wait_msec(40);
}



why?
please ingnore, I've just worked it out (doh), the second function never runs if the first one returns true.... :) (logical), or visa-versa if the code is executed backwards...

so mabe this is a better way ?

Code:

d = draw_object(sx+dirx,sy+diry);
e = draw_object(sx,sy);
//update screen
if (d || e)
{
update_screen();
//wait a little more....
wait_msec(40);
}

-Brendan
Yep, your first example falls into a trap that I posted about a week or two ago, where the second expression is not evaulated because the first value can determine the result of the whole expression if it is true.

Dan East