S
Steven Davies
I'm trying to iterate over an array, copying objects from one array into
another and "wrap around" over the boundary of the initial array, but I
have a problem:
I'm using the % operator to try and get the value to wrap around, but it
keeps jumping to negative numbers.
Here's a code snippet:
Does anyone have any idea why the statements at the bottom don't seem to
mod the number properly? Any more details you need, ask me
(oldX and oldY are definitely positive before this is executed, the
array called theTiles is 100 by 100.)
Thanks,
Steven Davies
another and "wrap around" over the boundary of the initial array, but I
have a problem:
I'm using the % operator to try and get the value to wrap around, but it
keeps jumping to negative numbers.
Here's a code snippet:
for (int x = 0; x < (sightDist * 2 + 1); x++) {
for (int y = 0; y < (sightDist * 2 + 1); y++) {
visibleArray[x][y] = theTiles[oldX][oldY];
oldY = (oldY + 1) % 100;
}
oldY = (oldY - (sightDist * 2 + 1)) % 100;
oldX = (oldX + 1) % 100;
}
Does anyone have any idea why the statements at the bottom don't seem to
mod the number properly? Any more details you need, ask me
(oldX and oldY are definitely positive before this is executed, the
array called theTiles is 100 by 100.)
Thanks,
Steven Davies