Hi. I have a project in which I am reading data from an accelerometer, where certain ranges of X, Y, & Z values correspond to certain scenarios. I then have to check to see if these scenarios are happening using if... statements. Here's an idea of how the code is now, and how I want it to be... (psuedo code)....
NOW:
if ("value of x" > insert AND "value of x" < insert AND "value of y" > insert AND "value of y" < insert)
{
DO A BUNCH OF STUFF }
WANT IT TO BE:
if (movingForwardRight)
{
DO A BUNCH OF STUFF }
movingForwardRight IS WHEN ("value of x" > insert AND "value of x" < insert AND "value of y" > insert AND "value of y" < insert)
I didn't really know the best way to word this question, but what is the best way to do something like this ?
Here's an idea of how the code is now
I'm pretty sure that that code won't compile. Post your real code.
You could create a macro that took several arguments, called movingForwardRight, but I don't recommend that.
Perhaps better would be to break the code down into a moving forward and a moving backward section. Make each section a function. In each section/function, determine if you are/should be moving left or right, and call the appropriate function.
Do the same, in those functions, for up and down, if needed.
It looks like you want to set movingForwardRight to true when
("value of x" > *insert* AND "value of x" < *insert* AND "value of y" > *insert* AND "value of y" < *insert*)
is true, but what the hell does:
movingForwardRight IS WHEN
mean?
I think you are wanting from the way you worded that:
boolean movingForwardRight = FALSE;
if ((x > xx && x < xz) && (y > yy && y < yz))
{
movingForwardRight = TRUE;
}
if (movingForwardRight){
//TODO
}
but in that case you could scrap off movingForwardRight and just use the condition.
a.mlw.walker:
I think you are wanting from the way you worded that:
boolean movingForwardRight = FALSE;
if ((x > xx && x < xz) && (y > yy && y < yz))
{
movingForwardRight = TRUE;
}
Or simply:
boolean movingForwardRight = (x > xx && x < xz) && (y > yy && y < yz);
Thanks everyone.. Yeah, the pseudo code I posted was kind of sloppy, and I didn't want to post my real code because the thing is pretty big and had a lot of other stuff. But I saw what you guys said and figured something out. I'll just have the 'if' statement contain all of my needed things, to figure out the situation, and then just do things from there, instead of referencing something else. Got it figured out now.