trouble with IF statement
Chuck Minton
Posts: 45
I am having trouble with this simple IF statement.
I'v done hundreds...but something is wrong and I am missing something here.
This loop is not supposed to keep cycling through this IF.
I am dumbfounded!
During this process, Playseconds is == 1
When Endflag turns to ==2, The next time through it should stop the recycle from happening, but does not. However
when PLAYSECONDS <>0 then the operations stops.
(sorry can't remember how to put the .spin in it's independent box)
I'v done hundreds...but something is wrong and I am missing something here.
This loop is not supposed to keep cycling through this IF.
I am dumbfounded!
During this process, Playseconds is == 1
When Endflag turns to ==2, The next time through it should stop the recycle from happening, but does not. However
when PLAYSECONDS <>0 then the operations stops.
(sorry can't remember how to put the .spin in it's independent box)
Repeat IF (ENDFLAG==1 AND PLAYSECONDS == 0) ENDFLAG:=2 ' STOP SECONDS FROM COUNTING DOWN ANY MORE DATA.str(VM1,STRING("VST",13)) '' STOP VMUSIC PLAYER OUTA[VM1P]~~ '' TURN VM AUDIO SW OFF OUTA[SATA]~ DATA.str(DEBUG,STRING("END VMUSIC PLAY",13,10))
Comments
Did you want to use a "repeat while ENDFLAG == 1 and PLAYSECONDS == 0"? This would stop repeating once ENDFLAG no long equaled one.
BTW, All caps are generally used or constant names. It looks really strange (as in wrong) to see all caps used on dynamic variables.
I've gotten used to using the formatting Parallax suggests for their Gold Standard objects. Now any other formatting styles look wrong to me (my problem not yours).
It is not supposed to leave loop, but if the condition exists then do the function.
does that make sense?
Then I agree, it should only execute the conditional code once since the ENDFLAG variable gets changed.
Sometimes there are problems in other parts of the code than originally expected. You'll need to post the rest of it in order for any of us to figure out the problem. If you have child objects, it would be good to attach the code as an archive.
I don't think that's the problem. Apparently the IF condition is continually met which is the problem.
It is very long loop. Also has a second cog that counts down the seconds.
I and sending the values back to Parallax serial Terminal, and the values count down to zero AND the ENDFLAG variable does equal 2.
I was wondering if I was just missing something in my brain right now and forgot how to make an IF statment
Sorry bout the caps. I have fuzzy Smile in my vision and I find it easier to read capitals that lower case.
I will keep at it until I find it , but appreciate the extra eyes!
Here is the length of the two cogs:
plus line from third
there is a single other line in a third cog as follows
But the associated debug to PST shows no repeated reset of the primary flag.
Thanks
Yes.. the problem is the Conditional is being met for exclusion , but the sub function of the conditional portion keeps being rendered.
Incomplete and poorly formatted code but the repeat is a repeat and no matter what the IF does there is nothing to stop it repeating, stop it repeating, stop it repeating
I think the original question just didn't make it clear this was part of a large loop (I'd assume the main loop of the program). I don't think the loop continuing to repeat is the problem (though my continuing to repeat may be one).
Apparently the text "END VMUSIC PLAY" is displayed each time the main loop is executed, which I gather is not what is expected.
@Chuck, You have at least two child objects in your program. The object "DATA" and the object "DEBUG". If you attach your code as an archive it would make it much easier for us to look at it.
To archive a program, make sure it has been compiled by pressing F8, F9, F10 or F11, then select File\Archive "Program Name"\Project...
My intent is NOT to stop the repeat of the IF statement !
I want the IF to be resolved every iteration!
I was just curious if I somehow had a wrong syntax of IF statement.
I can resolve the code loop otherwise.
I will go through the whole process again today and see what I come up with.
This project has 4 propellers talking to each other and gets in deep.
Simply ...is this the proper syntax for the if statement ??? That is all.
Thanks Duane for your input.
Sometimes is good to take a break!
As soon as I opened the code I saw the problem.
The problem is that as scene in the following: there is the line " IF ENDTIME==MINUTE"
Well this line was resetting the "ENDFLAG' redundantly because that statement was true for an
entire minute following.
So, simple. Thank you to all who bothered with suggestions.
Sorry 'bout the use of Code capitals, but is the only way I can work with my vision.
Solved!
You've got a plenty good enough of a reason to use all cap variables in my book.
I'm glad you found the bug.