Announcement

Collapse
No announcement yet.

Switch/Case not working with media_SetAdd

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Switch/Case not working with media_SetAdd

    I've got the following code that works fine (this example is extremely stripped down and all code that didn't matter was removed to debug the problem. I also reduced the code to only use 2 videos, but I'm using substantially more than that, with options of selecting what video to play.) When I run the below code, I get the expected two different videos with a pause between them:

    func main()

    while(!media_Init())
    putstr("Drive not mounted...");
    pause(400);
    gfx_Cls();
    pause(200);
    wend

    repeat

    media_SetAdd(iVideo1H, iVideo1L) ;
    media_Video(40, 35);

    pause(1000);
    gfx_RectangleFilled(41, 21, 159, 127, BLACK) ; //erase part of screen with old image

    media_SetAdd(iVideo2H, iVideo2L) ;
    media_Video(40, 35);

    pause(1000);
    gfx_RectangleFilled(41, 21, 159, 127, BLACK) ; //erase part of screen with old image

    forever

    endfunc

    But when I combine those two using a switch/endswitch to save on programming space, I don't get two different videos, I only get the last one, or Video2. I added a print statement to show which model should be showing and it flips between 1 and 2, but I only ever see #2. Why?

    func main()

    var ModelNum ;

    while(!media_Init())
    putstr("Drive not mounted...");
    pause(400);
    gfx_Cls();
    pause(200);
    wend

    repeat
    for (ModelNum := 1; ModelNum <= 2; ModelNum++)

    switch (ModelNum)
    case 1:
    media_SetAdd(iVideo1H, iVideo1L) ;
    case 2:
    media_SetAdd(iVideo2H, iVideo2L) ;
    endswitch

    gfx_MoveTo(10,10) ;
    print(ModelNum) ;
    media_Video(40, 35);

    pause(1000);
    gfx_RectangleFilled(41, 21, 159, 127, BLACK) ; //erase part of screen with old image
    next
    forever

    endfunc

    Rogi

  • #2
    You are missing 'Break's in your switch /case statements
    Mark

    Comment


    • #3
      Thanks for the heads up on that - that fixed it. Interestingly enough, the programming manual indicates in the syntax that they are optional, which is why I never thought to include them. Might need to update that since it appears that they are not optional, at least not always.

      Click image for larger version

Name:	Switch Syntax.jpg
Views:	190
Size:	44.6 KB
ID:	44300



      Comment


      • #4
        Gee, wonder what the correct wording is, should probably be 'as required', the only truly optional one is the last one
        Mark

        Comment

        Working...
        X