1 Reply Latest reply on Apr 10, 2010 10:41 PM by kglad

    Help with completing sentences game code

    angelowomon

      Hi, I`m a bit stuck, I`m making a game where you have to complete the sentences by dragging the words which are generated dinamically to its right place over some boxes, everything works fine but if you pull the words out of the boxes one all are placed it crashes.

       

      Unfortunately this is someone elses code (another programmer who bailed on us in the middle of the proyect) although I manage to make it work with new words, making the draggable items undraggable one you place all 4 of them in the right boxes is totally unclear to me. I`ll appreciate any help I can get.

       

      Here`s all the code that this part of the movie is using:

       

       

      function aleatorio(min, max)
      {
          var _loc2 = true;
          if (usados.length <= max - min)
          {
              while (_loc2 != false)
              {
                  var _loc1 = Math.floor(Math.random() * (max - min + 1));
                  _loc2 = repetido(_loc1);
              } // end while
              usados.push(_loc1);
              return (_loc1);
          }
          else
          {
              return (0);
          } // end else if
      } // End of the function
      function repetido(num)
      {
          var _loc1 = false;
          for (i = 0; i < usados.length; i++)
          {
              if (num == usados[i])
              {
                  _loc1 = true;
              } // end if
          } // end of for
          return (_loc1);
      } // End of the function
      stop ();
      var usados = new Array();
      _root.palabras_colocadas = 0;
      palabras_correctas = 0;
      listado_x = 700;
      listado_y = 400;
      origenx = 0;
      origeny = 0;
      estaba_en = -1;
      apagar = false;
      _root.frase = 2;
      var palabras = new Array("huts", "made", "mud", "straw");
      var correctas = new Array(false, false, false, false);
      var ocupadas = new Array(-1, -1, -1, -1);
      var my_font = new TextFormat();
      my_font.font = "Arial";
      my_font.color = 0;
      my_font.size = 30;
      palabras[i].embedFonts = true;
      my_font.bold = true;
      var i = 0;
      while (i < 4)
      {
          this["cuadro" + i].gotoAndStop(1);
          this.createEmptyMovieClip("myClip" + i, this.getNextHighestDepth());
          largo = palabras[i].length * 22;
          this["myClip" + i].createTextField("label", 1, 0, 0, largo, 40);
          this["myClip" + i].label.text = palabras[i];
          this["myClip" + i].label.setTextFormat(my_font);
          this["myClip" + i].onPress = function ()
          {
              temp = this._name;
              temp = Number(temp.charAt(6));
              if (ocupadas[0] == temp)
              {
                  apagar = true;
                  estaba_en = 0;
              } // end if
              if (ocupadas[1] == temp)
              {
                  apagar = true;
                  estaba_en = 1;
              } // end if
              if (ocupadas[2] == temp)
              {
                  apagar = true;
                  estaba_en = 2;
              } // end if
              if (ocupadas[3] == temp)
              {
                  apagar = true;
                  estaba_en = 3;
              } // end if
              if (!apagar)
              {
                  estaba_en = -1;
              } // end if
              origenx = this._x;
              origeny = this._y;
              trace ("estaba en " + estaba_en);
              this.startDrag();
          };
          this["myClip" + i].onRelease = this["myClip" + i].onReleaseOutside = function ()
          {
              this.stopDrag();
              cual = this._name;
              cual = Number(cual.charAt(6));
              drop = eval(this._droptarget);
              trace (drop);
              donde = String(drop);
              cuadro = donde.substr(8, 6);
              donde = Number(donde.charAt(14));
              trace (cual + " en " + donde + " " + cuadro);
              if (cuadro == "cuadro")
              {
                  if (ocupadas[donde] >= 0 && ocupadas[donde] <= 3 || donde == estaba_en)
                  {
                      apagar = false;
                      this._x = origenx;
                      this._y = origeny;
                  }
                  else
                  {
                      if (!apagar)
                      {
                          ++_root.palabras_colocadas;
                      } // end if
                      tramo = eval("tramo" + (donde + 1) + "_mc");
                      tramo.gotoAndPlay(2);
                      if (_root.palabras_colocadas >= 4)
                      {
                          startbtn.start();
                          start_mc.gotoAndPlay(2);
                      }
                      else
                      {
                          palabra_ok.start();
                      } // end else if
                      largo = palabras[cual].length * 8.500000E+000;
                      drop.gotoAndStop(2);
                      this._y = drop._y - 22;
                      this._x = drop._x - largo;
                      ocupadas[donde] = cual;
                      if (apagar)
                      {
                          apaga = eval("cuadro" + estaba_en);
                          apaga.gotoAndStop(1);
                          tramo = eval("tramo" + (estaba_en + 1) + "_mc");
                          tramo.gotoAndPlay(6);
                          ocupadas[estaba_en] = -1;
                          correctas[estaba_en] = false;
                          apagar = false;
                          trace ("hay " + _root.palabras_colocadas + " palabras");
                          if (_root.palabras_colocadas == 3)
                          {
                              trace ("apaga sin ruido");
                              start_mc.gotoAndStop(1);
                          } // end if
                      } // end if
                      trace (ocupadas[0] + " " + ocupadas[1] + " " + ocupadas[2] + " " + ocupadas[3]);
                      if (cual == donde)
                      {
                          ++palabras_correctas;
                          correctas[donde] = true;
                      } // end if
                  } // end if
              } // end else if
              if (cuadro == "myClip" || cuadro == "start_")
              {
                  palabra_error.start();
                  this._x = origenx;
                  this._y = origeny;
              } // end if
              if (cuadro == "fondo")
              {
                  if (apagar)
                  {
                      apaga = eval("cuadro" + estaba_en);
                      apaga.gotoAndStop(1);
                      tramo = eval("tramo" + (estaba_en + 1) + "_mc");
                      tramo.gotoAndPlay(6);
                      ocupadas[estaba_en] = -1;
                      correctas[estaba_en] = false;
                      --_root.palabras_colocadas;
                      apagar = false;
                      trace ("hay " + _root.palabras_colocadas + " palabras");
                      if (_root.palabras_colocadas == 3)
                      {
                          startbtn.start();
                          start_mc.gotoAndStop(1);
                      } // end if
                  } // end if
              } // end if
          };
          ++i;
      } // end while
      var ii = 0;
      while (ii < 4)
      {
          var numeroNuevo = aleatorio(1, 4);
          trace (numeroNuevo);
          this["myClip" + numeroNuevo]._x = listado_x;
          this["myClip" + numeroNuevo]._y = listado_y + 40 * i;
          ++ii;
      } // end while