Ask a Question related to Macromedia Director Basics, Design and Development.
-
domestic4 webforumsuser@macromedia.com #1
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
-
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... -
#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... -
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%'... -
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... -
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... -
Questy webforumsuser@macromedia.com #2
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
-
Desmond22 webforumsuser@macromedia.com #3
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



Reply With Quote

