Anixias
Member
So, I'm trying to loop through a buffer and find the list of numbers held in it.
Using buffer_read yields a much different result than buffer_peek (using some simple math to find the offset value).
So, simply put, I have 3 nested for loops to loop through a 3D grid. Each cell holds a u16 value, which are 2 byte positive integers (hence the multiplication by 2 for the offset). The buffer_read function always seems to read different numbers than my buffer_peek function (where offset = 2*(i+n*width+j*width*length))
Here is my code:
When I press shift, it outputs:
7 7 6 5 9 3 2 5 6 2 2 5 9 5 5 9 4 8 5 3 0 4 3 8 7 5 9
7 2 5 5 9 4 2 9 7 7 2 3 9 5 3 5 4 5 6 5 0 3 5 8 6 8 9
As you can see, they both hold 27 values (temporarily using a 3D grid of size 3x3x3) but they are reading different values. For all nested for loops, it goes width, length, height, so it isn't an issue with order or anything.
EDIT:
After a little bit of debugging, I discovered that the buffer_read list is identical to the list that is actually in the buffer, while buffer_peek is almost entirely incorrect.
EDIT:
I believe it probably is reading out of order. I looked up a script to tell me the frequency of characters in a string, and both lists contain the exact same frequencies per number, meaning they are probably containing the same data but in some incorrect order.
EDIT SOLVED:
So I decided to do the reverse order of the for loop and say offset = 2*(j+n*height+i*height*length) and it WORKED.
Using buffer_read yields a much different result than buffer_peek (using some simple math to find the offset value).
So, simply put, I have 3 nested for loops to loop through a 3D grid. Each cell holds a u16 value, which are 2 byte positive integers (hence the multiplication by 2 for the offset). The buffer_read function always seems to read different numbers than my buffer_peek function (where offset = 2*(i+n*width+j*width*length))
Here is my code:
Code:
var str = "";
var STR = "";
buffer_seek(chunk_buffer,buffer_seek_start,0);
for(var i = 0; i < width; i++)
{
for(var n = 0; n < length; n++)
{
for(var j = 0; j < height; j++)
{
var index = buffer_read(chunk_buffer,buffer_u16);
str += string(index)+" ";
STR += string(buffer_peek(chunk_buffer,2*(i+width*n+width*length*j),buffer_u16))+" ";
}
}
}
if keyboard_check_pressed(vk_shift)
{
show_debug_message(str);
show_debug_message(STR);
}
7 7 6 5 9 3 2 5 6 2 2 5 9 5 5 9 4 8 5 3 0 4 3 8 7 5 9
7 2 5 5 9 4 2 9 7 7 2 3 9 5 3 5 4 5 6 5 0 3 5 8 6 8 9
As you can see, they both hold 27 values (temporarily using a 3D grid of size 3x3x3) but they are reading different values. For all nested for loops, it goes width, length, height, so it isn't an issue with order or anything.
EDIT:
After a little bit of debugging, I discovered that the buffer_read list is identical to the list that is actually in the buffer, while buffer_peek is almost entirely incorrect.
EDIT:
I believe it probably is reading out of order. I looked up a script to tell me the frequency of characters in a string, and both lists contain the exact same frequencies per number, meaning they are probably containing the same data but in some incorrect order.
EDIT SOLVED:
So I decided to do the reverse order of the for loop and say offset = 2*(j+n*height+i*height*length) and it WORKED.
Last edited: