# cycle through 16 x and 16 y values, # which generate a total of 256 tile indexes for $y ( 0..15 ) { for $x ( 0..15 ) { # this calculates the tile index we are currently at, # using the x and y coords in this block $tile_index = $y+($x*16); # this calculates the real x and y values of this tile $rx = ($bx*16)+$x; $ry = ($by*16)+$y; # insert type data into the internal map array and # note that there was change in this block if applicable if ( !defined $tiles[$rx][$ry][$bz][type] || $tiles[$rx][$ry][$bz][type] != $type_data[$tile_index] ) { $changed = 1; $tiles[$rx][$ry][$bz][type] = $type_data[$tile_index]; } } } #### my ($rx,$ry,$y,$x,$tile); my $bxScaled = $bx * 16; my $byScaled = $by * 16; my $tile_index=0; for $x ( 0..15 ) { $rx = $bxScaled+$x; $tile = \$tiles[$bz][type][$rx]; for $y ( 0..15 ) { $ry = $byScaled+$y; if ( !defined $$tile->[$ry] || $$tile->[$ry] != $type_data[$tile_index] ) { $changed = 1; $$tile->[$ry] = $type_data[$tile_index]; } ++$tile_index; } }