Shop OBEX P1 Docs P2 Docs Learn Events
trouble with IF statement — Parallax Forums

trouble with IF statement

Chuck MintonChuck Minton Posts: 45
edited 2013-07-16 11:38 in Propeller 1
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)
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

  • ElectricAyeElectricAye Posts: 4,561
    edited 2013-07-15 16:28
    attachment.php?attachmentid=78421&d=1297987572
  • TinkersALotTinkersALot Posts: 535
    edited 2013-07-15 16:33
    the scope of spin logic is defined by indent levels (i don't mean to get us started on all that) -- but the code pasted has lost whatever indent there was. can you edit the post or try again to show the code?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-15 16:50
    How is it supposed to leave the repeat loop? I don't see a way out.

    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).
  • Chuck MintonChuck Minton Posts: 45
    edited 2013-07-15 16:54
    There are more if's in the loop.
    It is not supposed to leave loop, but if the condition exists then do the function.

    does that make sense?
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-15 16:59
    There are more if's in the loop.
    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.
  • Cluso99Cluso99 Posts: 18,069
    edited 2013-07-15 17:03
    According to your posted code, the REPEAT command will cause the IF.... to be continually be repeated.
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-15 17:24
    Cluso99 wrote: »
    According to your posted code, the REPEAT command will cause the IF.... to be continually be repeated.

    I don't think that's the problem. Apparently the IF condition is continually met which is the problem.
  • Chuck MintonChuck Minton Posts: 45
    edited 2013-07-15 17:55
    what is a child object?

    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
    PUB RUNTIME  (RUNTIMEvar)      
           
          OUTA [9..27]~~                                         'ALL SWITCHES ==1 >>> ALL SWITCHES OFF! 
          DIRA [9..27]~~
    
          ENDFLAG:=0    
          MINUTE:=(-1)
                                             
           ''  <<<<<<<<<<<<FOR TEST ONLY <<<<<<<<<<<<<<<   64 SECONDS             
               SECONDSfromF1000 := (0)
               SECONDSfromF100 :=(0)
               SECONDSfromF10 := (6)
               SECONDSfromF1 := (4) 
           ''  <<<<<<<<<<<<FOR TEST ONLY <<<<<<<<<<<<<<<  
      REPEAT
      
                
                
                IF FLAGF0==1                                 ''POFF 
                   FLAGF0:=0
                   OUTA[10..11]~~                         ''ALL "PROGRAM" SWITCHES ==1 >>> ALL SWITCHES OFF!                                                                              
                   OUTA[17..20]~~
                   OUTA[25..27]~~
              
                IF FLAGF1==1
                   FLAGF1:=0 
    
                IF FLAGF2==1
                   FLAGF2:=0                               '' A0FF
                   OUTA[9]~~                              ''ALL "AUDITION" SWITCHES ==1 >>> ALL SWITCHES OFF!                                                                              
                    OUTA[12..16]~~
                    OUTA[21..24]~~
              
                IF FLAG80==1
                   FLAG80:=0
                   OUTA[BLXP]~                                                    
                   ROM.WRITEBYTE($7FFC,1)  'BLX ON > TO MEMORY
                   LASTPROGRAM:=1
                   
                IF FLAG81==1
                   FLAG81:=0
                   OUTA[BLXP]~~
              
                IF FLAG82==1
                   FLAG82:=0
                   OUTA[SATP]~                                                   
                   ROM.WRITEBYTE($7FFC,2)  'SAT ON > TO MEMORY
                   LASTPROGRAM:=2
                    
                IF FLAG83==1
                   FLAG83:=0
                   OUTA[SATP]~~
             
                IF FLAG84==1
                   FLAG84:=0
                   OUTA[CONP]~                                                    
                   ROM.WRITEBYTE($7FFC,3)'CONSOLE ON > TO MEMORY
                   LASTPROGRAM:=3
                   
                IF FLAG85==1
                   FLAG85:=0
                   OUTA[CONP]~~
    
      
                IF FLAG86==1
                   FLAG86:=0
                   OUTA[VM1P]~
    
      
                IF FLAG87==1
                   FLAG87:=0
                   OUTA[VM1P]~~                                                   
    
      
                IF FLAG88==1
                   FLAG88:=0
                   OUTA[VM2P]~                                                   
    
      
                IF FLAG89==1
                   FLAG89:=0
                   OUTA[VM2P]~~
    
       
                IF FLAG8A==1
                   FLAG8A:=0
                   OUTA[AUX1P]~
                   ROM.WRITEBYTE($7FFC,4)'AUX1 ON > TO MEMORY
                   LASTPROGRAM:=4
                     
                IF FLAG8B==1
                   FLAG8B:=0
                   OUTA[AUX1P]~~
    
      
                IF FLAG8C==1
                   FLAG8C:=0
                   OUTA[AUX2P]~
                   ROM.WRITEBYTE($7FFC,5)'AUX2 ON > TO MEMORY
                   LASTPROGRAM:=5
                     
                IF FLAG8D==1
                   FLAG8D:=0
                   OUTA[AUX2P]~~
    
      
                IF FLAG8E==1
                   FLAG8E:=0
                   OUTA[AUX3P]~
                   ROM.WRITEBYTE($7FFC,6)'AUX3 ON > TO MEMORY
                   LASTPROGRAM:=6
                     
                IF FLAG8F==1
                   FLAG8F:=0
                   OUTA[AUX3P]~~
    
      
                IF FLAG90==1
                   FLAG90:=0
                   OUTA[AUX4P]~
                   ROM.WRITEBYTE($7FFC,7)'AUX4 ON > TO MEMORY
                   LASTPROGRAM:=7
                       
                IF FLAG91==1
                    FLAG91:=0
                    OUTA[AUX4P]~~
    
      
                IF FLAG92==1
                   FLAG92:=0
                   OUTA[BLXA]~
                   ROM.WRITEBYTE($7FFD,1)' BLX A > TO MEMORY
                   LASTAUDITION:=1 
    
                IF FLAG93==1
                   FLAG93:=0
                   OUTA[BLXA]~~
    
      
                IF FLAG94==1
                   FLAG94:=0
                   OUTA[SATA]~
                   ROM.WRITEBYTE($7FFD,2)' SAT A > TO MEMORY
                   LASTAUDITION:=2
                     
                IF FLAG95==1
                   FLAG95:=0
                   OUTA[SATA]~~
    
     
                IF FLAG96==1
                   FLAG96:=0
                   OUTA[CONA]~
                   ROM.WRITEBYTE($7FFD,3)' CON A > TO MEMORY
                   LASTAUDITION:=3
                     
                IF FLAG97==1
                   FLAG97:=0
                   OUTA[CONA]~~
        
                IF FLAG98==1
                   FLAG98:=0
                   OUTA[AIRA]~
                   ROM.WRITEBYTE($7FFD,4)' BLX A > TO MEMORY
                     LASTAUDITION:=4 
    
                IF FLAG99==1
                   FLAG99:=0
                   OUTA[AIRA]~~
    
                IF FLAGA2==1
                   FLAGA2:=0
                   OUTA[VM1A]~
    
                IF FLAGA3==1
                   FLAGA3:=0
                   OUTA[VM1A]~~
    
                IF FLAGA4==1
                   FLAGA4:=0
                   OUTA[VM2A]~
    
                IF FLAGA5==1
                   FLAGA5:=0
                   OUTA[VM2A]~~
    
     '' <<<<<<<<<<<<<<<<<<<<<<<  PLAY PUBLIC AFFAIRS <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                IF (FLAGB0==1)  AND  (DAY == 7)
                   FLAGB0:=0                                       
                   OUTA[10..11]~~                         ''ALL "PROGRAM" SWITCHES ==1 >>> ALL SWITCHES OFF!                                                                              
                   OUTA[17..20]~~
                   OUTA[25..27]~~
    
                  'EQUATE TO SPOTTIME 
                   SECONDSfromF :=((SECONDSfromF1000 ) * 1000)+ ((SECONDSfromF100 ) * 100)+ ((SECONDSfromF10) * 10)+ (SECONDSfromF1)  <# 3540   'LIMIT TO 59 MINUTES
    
                   PLAYMINUTES:=SECONDSfromF/60         'EQUALS MINUTES MAX 59
                   PLAYSECONDS:=(SECONDSfromF//(60))  ' EQUALS SECONDS     DEC FRACTLE.../100==%... X 60 SEC PER MIN... 'REALIZE MODULUS OF REMAINING MINUTE >> CREATE SECONDS COUNT DOWN VALUE 
                   ENDTIME:= PLAYMINUTES + MINUTE                     'READ CURRENT MINUTE   'ADD RUN MINUTES TO CRUURENT MINUTE  
                   IF ENDTIME>59                                   ' RECALCULATE...IF TIME GOES OVER THE TOP OF HOUR ON MINUTES
                      ENDTIME:=ENDTIME-60                                '  ...ADJUST FOR THE OVER 60 CARRY MINUTES 
    
     
                   OUTA[VM1P]~                                     'TURN ON DG411 AUDIO SWITCH : TIE-IN VM PLAYER TO PROGRAM OUTPUT
                   ENDFLAG:=0                                      'ALLOW COUNT SECONDS COUNT DOWN TIMER TO COUNT WHEN NEEDED
    
          
                   DATA.STR(VM1,STRING("vpf "))                         '' talk to VMusic player
                   DATA.TX(VM1,MONTHascii) ' ALPHA DESIGNATOR A-L
                   data.DEC(VM1,DAY)
                   data.DEC(VM1,DATENUM10)
                   DATA.DEC(VM1,DATENUM1)
                   DATA.DEC(VM1,SECONDSfromF1000)
                   DATA.DEC(VM1,SECONDSfromF100)
                   DATA.DEC(VM1,SECONDSfromF10)
                   DATA.DEC(VM1,SECONDSfromF1)
                   DATA.STR(VM1,STRING(".mp3",13))
       
    ''<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< PLAY PA vm1NEXT   RT==1  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                                                            
                IF FLAGB1==1
                   FLAGB1:=0                                       
                   DATA.str(DEBUG,STRING("PLAY VM1 next# ",13,10))
                   '' DO SOMETHING
                IF FLAGB2==1                                            
                   FLAGB2:=0                                         ''PLAYvm1NEXT       RT==2 
                   DATA.str(DEBUG,STRING("PLAY VM1 TEST ID ",13,10))
                   '' DO SOMETHING                                   ''PLAYvm1TEST       RT==3
                IF FLAGB3==1                                                     
                   FLAGB3:=0
                   DATA.str(DEBUG,STRING("PLAY VM2 next# ",13,10))
                  '' DO SOMETHING                                     ''PLAYvm2NEXT       RT==4 
                IF FLAGB4==1                                             
                   FLAGB4:=0
                   DATA.str(DEBUG,STRING("PLAY VM2 TEST ID ",13,10))  ''PLAYvm2TEST        RT==5 
                   '' DO SOMETHING                                           
    
    
       '' <<<<<<<<<<<<  TURN OFF VMUSIC PLAYER WHEN FINISHED <<<<<<<<<<<<<<<<<<<<<<<
    
                           
                      'CHECK WHEN MINUTE IS DONE   >  SWITCH TO COUNT DONW SECONDS
                      'WHEN MINUTE AND SECOND IS DONE > SWITCH OFF VM
                      
              DATA.DEC(DEBUG, ENDTIME)                          '' help debugging
              DATA.TX(DEBUG,44)
              DATA.DEC(DEBUG, MINUTE)
              DATA.TX(DEBUG,44)
              DATA.DEC(DEBUG, PLAYSECONDS)   
              DATA.TX(DEBUG,44)      
              DATA.DEC(DEBUG, ENDFLAG)     
              DATA.TX(DEBUG,13)
             
                IF ENDTIME==MINUTE                          'TOGGLE TO START SECONDS COUNT DOWN
                      ENDFLAG:=1                   
                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))
             '       OUTA[SATP]~
                    LASTprogramON
                    waitcnt(clkfreq+cnt)                            ' RETURN TO THE LAST AUDIO INPUT 
                    DATA.str(VM1,STRING("VST",13))                   '' STOP VMUSIC PLAYER 
                                     
                   
     ''  $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
    PUB   CLOCK (CLOCKretVAR)       '' COUNT SECONDS PASSAGE AND COUNT UP. IF OVER 59 RETUREN TO 00 AND START OVER
          CTRA[30..26]:=%11111                              ' ALWAYS ADD FRQA TO PHSA!
          FRQA:=1                                           ''USE OF INTERNAL COG COUNTER 
          PHSA:=0 
        '  CTRB[30..26]:=%11111                              ' ALWAYS ADD FRQA TO PHSb!
        '  FRQB:=1                                           ''USE OF INTERNAL COG COUNTER 
        '  PHSB:=0 
    
    
            REPEAT
               IF PHSA >79_500_000
                  PHSA:=0
                  IF ENDFLAG==1
                     PLAYSECONDS-- 
    
     
    

    there is a single other line in a third cog as follows
       repeat
             ''lots of other flags here
              
              $B0: FLAGB0:=1 '' PLAY PA                                            '' VMUSIC PLAY COMMANDS
                      DATA.STR(DEBUG,STRING(" $B0 FLAG RECIEVED !") )  
    

    But the associated debug to PST shows no repeated reset of the primary flag.

    Thanks
  • Chuck MintonChuck Minton Posts: 45
    edited 2013-07-15 17:57
    Duane Degn wrote: »
    I don't think that's the problem. Apparently the IF condition is continually met which is the problem.

    Yes.. the problem is the Conditional is being met for exclusion , but the sub function of the conditional portion keeps being rendered.
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2013-07-15 18:01
    Duane Degn wrote: »
    I don't think that's the problem. Apparently the IF condition is continually met which is the problem.

    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
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-15 20:49
    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...
  • Chuck MintonChuck Minton Posts: 45
    edited 2013-07-16 07:45
    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

    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.
  • Chuck MintonChuck Minton Posts: 45
    edited 2013-07-16 10:12
    Soooo the solution was obvious... and being stumped is only a end of being tooo long staring at the same problem with the same solutions flowing through your mind...
    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:
                IF ENDTIME==MINUTE                          'TOGGLE TO START SECONDS COUNT DOWN
                      ENDFLAG:=1                   
                IF (ENDFLAG==1 AND PLAYSECONDS == 0)
                    ENDFLAG:=2                                        ' STOP SECONDS FROM COUNTING DOWN ANY MORE
                    DATA.str(VM1,STRING("VST",13))
    
    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!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2013-07-16 11:38
    Sorry 'bout the use of Code capitals, but is the only way I can work with my vision.

    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.
Sign In or Register to comment.