Copy link to clipboard
Copied
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???
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 .
Copy link to clipboard
Copied
are you improperly setting a while-limit and not completing those loops?
Copy link to clipboard
Copied
The code is finishing as it should be. The while loop finishes, but somewhere the matchHoriz array is losing it's values.
Copy link to clipboard
Copied
then check getHorizMatch() for any matchHoriz maniuplation
Copy link to clipboard
Copied
When you clear match, you clear the references to it that you've pushed into matchHoriz.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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 .
Find more inspiration, events, and resources on the new Adobe Community
Explore Now