I call a function which looks like this, and it keeps looping by resetting itself, this code is also in a function, which has a for loop that sets flip, and once the for loop is done calls checkFlip(), and then does another for loop and checkFlip(). The problem with this code it it sets flip to false and then comes back around somehow and sees that its true
You didn't post enough code for us to determine the problem. Anyway, I felt the need to simplify the code you did post in an attempt to help. Don't take this the wrong way but your code was a bit overly complicated.
X Abstract X wrote:You didn't post enough code for us to determine the problem. Anyway, I felt the need to simplify the code you did post in an attempt to help. Don't take this the wrong way but your code was a bit overly complicated.
X Abstract X wrote:You didn't post enough code for us to determine the problem. Anyway, I felt the need to simplify the code you did post in an attempt to help. Don't take this the wrong way but your code was a bit overly complicated.
void checkFlip() {
if (flip) {
flip = false;
} else {
for (int i = 0; i < 7; i++)
flip();
}
}
you didnt change the code really you just used a else instead of a else if, its no more less complicated, if anything his is easier to read.
I'd say his loop is damn hard to read. You could argue that the rest is personal preference but it's bloated in my opinion. Forums are a place for everyone to pitch in opinions and people can take from it what they want, I'm not claiming my preference is gold.
flip = false; // flip is a variable ?
flip(); // or is it a function...
The only reason it works is because C++ defines functions not just by their name but also their parameters. func(void) (a function, also written as func())is different from just plain func (the variable).
Anyway, looking at the original problem, you're using mutual recursion without a condition to stop it. We'll need to see the code for flip() as well as checkFlip().
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
You need to provide more code. We need to see where "flip" is modified to true, if it ever is.
Taking a look at the code, flip is quite useless. When you call "checkFlip()" you first see if flip is false, lets just say it is, so the code will start the loop, which will halt your game execution until it is done. I am assuming flip() sets flip to false at the end? So, the sequences goes like this
check flip if false
flip is false
repeat flip() seven times
flip is still false
if flip is true (which it seems it cant be)
set flip to false
Right now, it looks like a function that just starts another function... flip is probably only set to true in your flip() function.
I think what you want, is a counting sequence that will execute along with your overall loop.
pythip wrote:I call a function which looks like this, and it keeps looping by resetting itself, this code is also in a function, which has a for loop that sets flip, and once the for loop is done calls checkFlip(), and then does another for loop and checkFlip(). The problem with this code it it sets flip to false and then comes back around somehow and sees that its true
void checkFlip()
{
if (flip == false)
{
for (int i = 1; i<=7; i+=1)
{
flip();
}
}
else if (flip == true)
{
flip = false;
}
}
if you want to stop the looping you can use the break; statements;
When break statement is call cursor position transfer outside the for loop.
try this statement to stop your for loop.
MacJordan wrote:
if you want to stop the looping you can use the break; statements;
When break statement is call cursor position transfer outside the for loop.
try this statement to stop your for loop.
Appreciate you trying to help, but please read the last post date before posting. This thread is over 5 months old.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!