Ask a Question related to Macromedia Director Basics, Design and Development.

  1. #1

    Default Nested loop woes.

    Hi,

    I am quite new to using Director and am having some trouble with some nested loops. I am trying to create a drum machine, whereby users program a drum pattern by toggling a button on a grid style sequencer (the interface is similar to that of a Roland 808 drum machine). I am writing some test code at present to store samples in a multi-dimensional list. I have then written a handler to loop through the list and play any samples contained within the list. My big problem at the moment is that I need to loop through my main list again and again until the user presses a stop button, but am having trouble doing this. With the code at present, Director crashes everytime. I think that one pass of the list is performed before the crash.

    Have attached the code. Any suggestions would be greatly appreciated, also any other suggestions would be welcomed.

    Thanks, miles.

    global glistMain, gKickVolume, gHatVolume, gSnareVolume, gIsPlaying

    on startmovie
    -- initialize volumes
    gKickVolume = 150
    gSnareVolume = 150
    gHatsVolume = 150
    gIsPlaying = false

    -- queue sounds
    sound(2).queue(member"HIP_KICK4")
    sound(3).queue(member"808_SNARE1")
    sound(4).queue(member"ELEC_CHAT2")

    -- set volumes
    sound(2).volume = gKickVolume
    sound(3).volume = gSnareVolume
    sound(4).volume = gHatsVolume

    -- set master volume
    setMasterVolume(5)

    -- initialize a multi-dimensional list with pointers to samples being used
    set glistMain = [["a","c"],[VOID],["c"],[VOID],["c","b"],[VOID],["c"]]
    end

    on setMasterVolume masterLevel
    the soundLevel = masterLevel
    end

    -- handler to loop through list and play samples
    on playDrumgrid
    repeat while gIsPlaying=true
    repeat with i = 1 to count(glistMain)
    repeat with j = 1 to count(getAt (glistMain, i))
    if getAt(getAt (glistMain, i), j)="a" then
    sound(2).play()
    else if getAt(getAt (glistMain, i), j)="b" then
    sound(3).play()
    else if getAt(getAt (glistMain, i), j)="c" then
    sound(4).play()
    end if
    end repeat
    set j = 1
    end repeat
    set i = 1
    end repeat
    end

    -- handler for play button
    on startPlaying
    gIsPlaying = true
    playDrumgrid
    end

    -- handler for stop button
    on stopPlaying
    gIsPlaying = false
    end



    domestic4 webforumsuser@macromedia.com Guest

  2. Similar Questions and Discussions

    1. XML nested Loop?
      hi all. I´ve just completed a little test for making a tree component with custom icons / bransch. However, i can only get my first branch to...
    2. #40768 [NEW]: nested foreach break -- infinite loop - serious
      From: rave235 at gmail dot com Operating system: winxp PHP version: 5.2.1 PHP Bug Type: Scripting Engine problem Bug...
    3. Nested Loop
      Hi I am attempting to output this data using a table but things do output very well. Do I need nested looping. Thanks <table width='100%'...
    4. Film loop rollovers working with tell sprite, but only if Loop is checked
      on mouseWithin me cursor 280 tell sprite 40 --the sprite containing the film loop sprite(60).member = member("networkmapsbuttonroll") --swapping...
    5. Question on Dynamic Array/Nested Loop approach
      Hello, I have the following code which populates as table data from a SQL Server 2000 stored proc (RSByDemoID2). Below that is the view and...
  3. #2

    Default Re:Nested loop woes.

    You've got a potentially never ending loop inside the movie script, and no way of breaking out of it unless the playback head moves into a new frame (in which case a stop button or something might have a chance to work.)

    You need to re-think this to allow endframe events to occur inside the loop. You might want to set up a counter for each dimension of the array, and then put an on endframe handler in the movie script.


    Andrew Quested
    [url]http://www.quested.com.au[/url]
    Questy webforumsuser@macromedia.com Guest

  4. #3

    Default Re:Nested loop woes.

    Hi,

    Like Andrew Quested said you have never ending loops.
    take out the lines:

    I'm in an internet cafe so can't really test this but why don't you change:

    repeat while gIsPlaying=true
    to
    if gIsPlaying= true then

    blah blah blah


    Desmond22 webforumsuser@macromedia.com Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139