Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

AS3 Code problem

Explorer ,
Aug 03, 2014 Aug 03, 2014

I wrote this code:

match = new Array();

matchHoriz = new Array();

row = 0;

while (row < gridRows)

{

      col = 0;

     while (col < gridCols)

     {

          match = getHorizMatch (row, col);

          if (match.length > 1)

          {

               match.unshift(grid[row][col]);

               matchHoriz.push(match);

              // ***1        

          }

          if (match.length == 0)

          {

               col++;

          }

          else

          {

               col = col + match.length;

          }

          match.length = 0;

     }

     row ++;

}

// ***2

If I place trace(matchHoriz) on position // ***1 it shows the correct result (an array with matched objects).

If I place trace(matchHoriz) on position // ***2 it doesn't show anything.

What is wrong about my code???

TOPICS
ActionScript
403
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Aug 05, 2014 Aug 05, 2014

Correct, when you change to concat, you're no longer putting in a reference to the match array. Instead, you're copying its contents, which is what you apparently thought you were doing before .

Translate
Community Expert ,
Aug 03, 2014 Aug 03, 2014

are you improperly setting a while-limit and not completing those loops?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 03, 2014 Aug 03, 2014

The code is finishing as it should be. The while loop finishes, but somewhere the matchHoriz array is losing it's values.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2014 Aug 04, 2014

then check getHorizMatch() for any matchHoriz maniuplation

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 04, 2014 Aug 04, 2014

When you clear match, you clear the references to it that you've pushed into matchHoriz.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 05, 2014 Aug 05, 2014

Before I clear the match array, the array is added to the array matchHoriz so the data should be there no matter what I do with match array data. I figured out what was happening: when I add the match array with push, the data in the matchHoriz array doesn't look as I expected. I changed push with concat and everything is going right now.

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 05, 2014 Aug 05, 2014
LATEST

Correct, when you change to concat, you're no longer putting in a reference to the match array. Instead, you're copying its contents, which is what you apparently thought you were doing before .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines