O
oziphantom
Guest
lets start with the code
Been having a lot of fun with this as you can probably tell.
apparently if you use array_create you then can't use array[number] on it, as its "not an array"
but all the cloning and copying works up until it tries to go again.
Here is a print out of what happens when it runs
The first pass it adds points, which are custom copies of the point so they don't trash each other, even when they are in scope { } and a new var. So they should hold their values, but after I swap the stacks over, it still has 4 points in it, just now the point is [ ] and not its value . If you just print a stack you get the ID number and not an meaningful data, the debugger also can't "see inside of them".
So what do I need to do to make the stack holds the values?
Code:
function getValidMoveSquares(startPos, distance, unitType, team)
{
var moveData;
for (var i = 0; i < distance*2+1; ++i)
{
for (var j=0; j< distance*2+1; ++j)
{
moveData[i][j] = 255;
}
}
var openPositions = ds_stack_create();
var dummy = array_create(2);
dummy[0] = startPos[0]
dummy[1] = startPos[1]
ds_stack_push(openPositions, dummy);
var travel = 0;
do
{
var newOpenPositions = ds_stack_create();
if(travel < distance) // this need to be inside the loop
{
show_debug_message("looking at distance : "+string(travel));
show_debug_message("num points: "+string(ds_stack_size(openPositions)));
while(ds_stack_size(openPositions) > 0)
{
var testPos = ds_stack_pop(openPositions);
show_debug_message("test pos : "+string(testPos));
var offsetTestPos1;
offsetTestPos1[0] = testPos[0]
offsetTestPos1[1] = testPos[1]-1
if( canMoveTo(offsetTestPos1,unitType,team) )
{
if (updateDistanceAt(moveData,offsetTestPos1,startPos,travel))
{
show_debug_message("adding pos : "+string(offsetTestPos1));
var dummy = array_create(2);
array_set(dummy,0, offsetTestPos1[0]);
array_set(dummy,1, offsetTestPos1[1]);
ds_stack_push(newOpenPositions, dummy);
show_debug_message(" dummy : " + string(dummy));
show_debug_message("num points: "+string(ds_stack_size(newOpenPositions)));
}
}
var offsetTestPos2;
offsetTestPos2[0] = testPos[0]-1
offsetTestPos2[1] = testPos[1]
if( canMoveTo(offsetTestPos2,unitType,team) )
{
if (updateDistanceAt(moveData,offsetTestPos2,startPos,travel))
{
show_debug_message("adding pos : "+string(offsetTestPos2));
var dummy = array_create(2);
array_set(dummy,0, offsetTestPos2[0]);
array_set(dummy,1, offsetTestPos2[1]);
ds_stack_push(newOpenPositions, dummy);
show_debug_message("num points: "+string(ds_stack_size(newOpenPositions)));
}
}
var offsetTestPos3;
offsetTestPos3[0] = testPos[0]
offsetTestPos3[1] = testPos[1]+1
if( canMoveTo(offsetTestPos3,unitType,team) )
{
if (updateDistanceAt(moveData,offsetTestPos3,startPos,travel))
{
show_debug_message("adding pos : "+string(offsetTestPos3));
var dummy = array_create(2);
array_set(dummy,0, offsetTestPos3[0]);
array_set(dummy,1, offsetTestPos3[1]);
ds_stack_push(newOpenPositions, dummy);
show_debug_message("num points: "+string(ds_stack_size(newOpenPositions)));
}
}
var offsetTestPos4;
offsetTestPos4[0] = testPos[0]+1
offsetTestPos4[1] = testPos[1]
if( canMoveTo(offsetTestPos4,unitType,team) )
{
if (updateDistanceAt(moveData,offsetTestPos4,startPos,travel))
{
show_debug_message("adding pos : "+string(offsetTestPos4));
var dummy = array_create(2);
array_set(dummy,0, offsetTestPos4[0]);
array_set(dummy,1, offsetTestPos4[1]);
ds_stack_push(newOpenPositions, dummy);
show_debug_message("num points: "+string(ds_stack_size(newOpenPositions)));
}
}
array_delete(dummy,0,2)
} //while(ds_stack_size(newOpenPositions) > 0)
show_debug_message("new num points: "+string(ds_stack_size(newOpenPositions)));
ds_stack_destroy(openPositions);
openPositions = newOpenPositions;
show_debug_message("num points: "+string(ds_stack_size(openPositions)));
travel += 1;
} //if(travel < distance)
else
{
ds_stack_clear(openPositions); // we are over movement, we don't care about them any more
}
} until( ds_stack_size(openPositions) == 0 )
ds_stack_destroy(openPositions);
return moveData;
}
apparently if you use array_create you then can't use array[number] on it, as its "not an array"
but all the cloning and copying works up until it tries to go again.
Here is a print out of what happens when it runs
Code:
looking at distance : 0
num points: 1
test pos : [ 9,5 ]
adding pos : [ 9,4 ]
dummy : [ 9,4 ]
num points: 1
adding pos : [ 8,5 ]
num points: 2
adding pos : [ 9,6 ]
num points: 3
adding pos : [ 10,5 ]
num points: 4
new num points: 4
num points: 4
looking at distance : 1
num points: 4
test pos : [ ]
So what do I need to do to make the stack holds the values?