I need your brillian minds.....

  • meAsking
  • Beginner
  • Beginner
  • meAsking
  • Posts: 38

Post 3+ Months Ago

Hey good people,
I need someone's help. I've been working on this code for the past 3 days! I am trying to built a simon game (the memory game of sounds in a sequence). sorry to post the whole code here, but it might help to figure out what's wrong.
so when i click the start button one sound goes off and then the user clicks. let say the user gets it right, then counter = 1. then, the second sound goes off. then the user clicks sound one and two. then counter = 2. till now it's fine. but after this, push array doesn't get anymore sounds pushed in. actually no other sounds come up any more! so in total only 2 sounds come up.
I'm thinking the problem might be with gotoAndStop at frame2. I can't figure it out. I need your brilliant minds please please... (I'll appreciate it forever!)

Code: [ Select ]
stop();
var sound = new Sound();
var soundArray = new Array("1", "2", "3", "4");
var pushArray = new Array();
var counter = 0;
//-----------------------------------------------------------
for (i=1; i<5; i++) {
    _root["mc"+i].gotoAndStop(1);
    _root["mc"+i].id = i;
    //-----------------------when pressing any mc
    _root["mc"+i].onPress = function() {
        playSound(this.id);
        compareSound(this.id, pushArray[counter]);
    };
}
but.onRelease = function() {
    randAllSound();
};
function randAllSound() {
    var rand = Math.floor(Math.random()*soundArray.length);
    playSound(soundArray[rand]);
    storeSound(soundArray[rand]);
}
function playSound(num) {
    a = "audio"+num;
    sound.attachSound(a);
    sound.start();
    //assigning button to sound
    if (a == "audio1") {
        mc1.gotoAndPlay(2);
    }
    if (a == "audio2") {
        mc2.gotoAndPlay(2);
    }
    if (a == "audio3") {
        mc3.gotoAndPlay(2);
    }
    if (a == "audio4") {
        mc4.gotoAndPlay(2);
    }
}

function storeSound(a) {
    pushArray.push(a);
}

function compareSound(p1, p2) {
    if (p1 == p2) {
        counter++;
        trace("counter"+counter);
        sound.onSoundComplete = function() {
            trace("soundComplete+goto2");
            gotoAndStop(2);
        };
        if (counter == pushArray[counter]){
            gotoAndStop(2);
        }
    }
    else {
        wrong.gotoAndPlay(2);
    }
}
  1. stop();
  2. var sound = new Sound();
  3. var soundArray = new Array("1", "2", "3", "4");
  4. var pushArray = new Array();
  5. var counter = 0;
  6. //-----------------------------------------------------------
  7. for (i=1; i<5; i++) {
  8.     _root["mc"+i].gotoAndStop(1);
  9.     _root["mc"+i].id = i;
  10.     //-----------------------when pressing any mc
  11.     _root["mc"+i].onPress = function() {
  12.         playSound(this.id);
  13.         compareSound(this.id, pushArray[counter]);
  14.     };
  15. }
  16. but.onRelease = function() {
  17.     randAllSound();
  18. };
  19. function randAllSound() {
  20.     var rand = Math.floor(Math.random()*soundArray.length);
  21.     playSound(soundArray[rand]);
  22.     storeSound(soundArray[rand]);
  23. }
  24. function playSound(num) {
  25.     a = "audio"+num;
  26.     sound.attachSound(a);
  27.     sound.start();
  28.     //assigning button to sound
  29.     if (a == "audio1") {
  30.         mc1.gotoAndPlay(2);
  31.     }
  32.     if (a == "audio2") {
  33.         mc2.gotoAndPlay(2);
  34.     }
  35.     if (a == "audio3") {
  36.         mc3.gotoAndPlay(2);
  37.     }
  38.     if (a == "audio4") {
  39.         mc4.gotoAndPlay(2);
  40.     }
  41. }
  42. function storeSound(a) {
  43.     pushArray.push(a);
  44. }
  45. function compareSound(p1, p2) {
  46.     if (p1 == p2) {
  47.         counter++;
  48.         trace("counter"+counter);
  49.         sound.onSoundComplete = function() {
  50.             trace("soundComplete+goto2");
  51.             gotoAndStop(2);
  52.         };
  53.         if (counter == pushArray[counter]){
  54.             gotoAndStop(2);
  55.         }
  56.     }
  57.     else {
  58.         wrong.gotoAndPlay(2);
  59.     }
  60. }



------frame 2 has:
randAllSound();
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • lostinbeta
  • Guru
  • Guru
  • User avatar
  • Posts: 1402
  • Loc: Philadelphia, PA

Post 3+ Months Ago

A problem like this would be much easier to debug if we could have a look at the source files.

Some things I noticed...

This function
Code: [ Select ]
function playSound(num) {
  a = "audio"+num;
  sound.attachSound(a);
  sound.start();
  //assigning button to sound
  if (a == "audio1") {
   mc1.gotoAndPlay(2);
  }
  if (a == "audio2") {
   mc2.gotoAndPlay(2);
  }
  if (a == "audio3") {
   mc3.gotoAndPlay(2);
  }
  if (a == "audio4") {
   mc4.gotoAndPlay(2);
  }
}
  1. function playSound(num) {
  2.   a = "audio"+num;
  3.   sound.attachSound(a);
  4.   sound.start();
  5.   //assigning button to sound
  6.   if (a == "audio1") {
  7.    mc1.gotoAndPlay(2);
  8.   }
  9.   if (a == "audio2") {
  10.    mc2.gotoAndPlay(2);
  11.   }
  12.   if (a == "audio3") {
  13.    mc3.gotoAndPlay(2);
  14.   }
  15.   if (a == "audio4") {
  16.    mc4.gotoAndPlay(2);
  17.   }
  18. }


I noticed a patter..

audio1 = mc1

audio2 = mc2

audio3 = mc3

You can save yourself the if statments by doing this
Code: [ Select ]
function playSound(num) {
  sound.attachSound("audio"+num);
  sound.start();
  //assigning button to sound
this["mc"+num].gotoAndPlay(2);
}
  1. function playSound(num) {
  2.   sound.attachSound("audio"+num);
  3.   sound.start();
  4.   //assigning button to sound
  5. this["mc"+num].gotoAndPlay(2);
  6. }
I believe I posted a link or some information to associative array referencing in a previous thread at this forum if you aren't sure whats going on there.

And another thing I noticed is that counter never gets reset back to 0. Not sure if it's supposed to or not, but I would assume it would need to be if you get it wrong and it has to start over.

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 17 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.