roidman wrote:bool a = false;
if(....)
a=!a
does not work...
I'm assuming you initialized bool a. inside the main code block, like so:
- Code: Select all
main{
bool a = FALSE;
if(...)
a=!a;
}
If this is correct?, then of course its not going to work lol. Because the main code block gets called every ms. and bool a is continuously going to be called, and assigned FALSE.
Here are a few ways to get around this.
You could make "bool a", a global variable instead, This is the ideal solution.
Example 1- Code: Select all
bool a = FALSE;
main{
if(...)
a=!a;
}
Another solution, would be to just declare bool a by it self. Don't assign it a value. when you place it in the main code block.
Example 2- Code: Select all
main{
bool a;
if(...)
a=!a;
}
A third solution, which is equivalent to the above example. Is to declare your variable as a static bool. A static type can be assigned a value, and you wont have to worry about the value being re-assigned every time the main code block is called. As it will remember its last state.
Example 3- Code: Select all
main{
static bool a = FALSE;
if(...)
a=!a;
}
although just keep in mind, static bool a = FALSE; is equivalent to just declaring bool a; by it self.
A static bool variable initialized in the main code block is beneficial, if you want to assign the value TRUE; So If you want to assign it FALSE, just stick with Example 2.