3 Replies Latest reply on Aug 17, 2010 7:05 PM by Ned Murphy

    Something wrong with comparison result

    zoldol

      Hi All,

      I have a problem that bugging me and hindering me from advancing to next part of the game. I'm very much behind schedule because of these weird behavior. (Well I blame my ignorance for not properly coding them)

       

      I'm trying to do a simple click-and-match game where there are 18 items to flip but only 10 items (5 pairs) are the valid answer. The problem lies with this part:

       

      if (FirstItem == arrPRearranged[ChipIdx])

       

      It doesn't detect any match at all. Is there any misstype of data on the things that I'm comparing with?

       

      Please help and thank you in advance.

       

       

      So, the code as below:

       

      stop();

      var arrI:Array = new Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18);

      var arrP:Array = new Array("CheckItem1", "CheckItem2", "CheckItem3", "CheckItem4", "CheckItem5", "CheckItem1", "CheckItem2", "CheckItem3", "CheckItem4", "CheckItem5", "11", "12", "13", "14", "15", "16", "17", "18");

      var FirstClick:MovieClip;

      var SecondClick:MovieClip;

      var FirstItem:String = null;

      var IntervalID:Number;

      var arrIRearranged:Array = new Array();

      var arrPRearranged:Array = new Array();

      var J:Number = arrI.length;

      for (l=0; l<J; l++) {

      m = arrI.length;

      ranIdx = random(m);

      xtractI = arrI.splice(ranIdx, 1);

      xtractP = arrP.splice(ranIdx, 1);

      arrIRearranged.push(xtractI);

      arrPRearranged.push(xtractP);

      }

      for (i=0; i<18; i++) {

      this["Item"+arrIRearranged[i]]._x = this["sq"+i]._x;

      this["Item"+arrIRearranged[i]]._y = this["sq"+i]._y;

      }

      function ClosePair(Lid1, Lid2) {

      clearInterval(IntervalID);

      Lid1._x -= 1000;

      Lid2._x -= 1000;

      FirstClick = null;

      FirstItem = null;

      SecondClick = null;

      }

      function CheckChip(myChip:MovieClip, ChipIdx:Number) {

      if (SecondClick == null) {

      myChip._x += 1000;

      if (FirstClick == null) {

      FirstClick = myChip;

      FirstItem = arrPRearranged[ChipIdx];

      trace("FirstItem="+FirstItem);

      } else {

      SecondClick = myChip;

      trace("FirstItem="+FirstItem+"  "+"SecondItem="+arrPRearranged[ChipIdx]);

      if (FirstItem == arrPRearranged[ChipIdx]) { // ----> this part doesn't detect any match at all

      trace("Matched");

      _parent.TickItem(FirstItem);

      } else {

      clearInterval(IntervalID);

      IntervalID = setInterval(ClosePair, 500, FirstClick, myChip);

      }

      }

      }

      }

      sq0.onRelease = function() {

      CheckChip(this,0);

      };

      sq1.onRelease = function() {

      CheckChip(this,1);

      };