[SOLVED] Buffer poke writes to two buffers

Bentley

Member
Edit solved: It seems like I needed to pass to the script the buffer IDs. If I wrote to the buffers in the script directly (without passing them in as arguments), they got all screwy.

I have two buffers, "white_pawns" and "white_king". But when I write to the white_pawns buffer, it also writes to the white_king buffer, and vice versa.

Edit: Sometimes the buffer id's are the same when I check: buffer_get_address().

Here's the code:
[Create]
Code:
white_pawns = buffer_create(64, buffer_fixed, 1);
white_king  = buffer_create(64, buffer_fixed, 1);

white_pawns = buffer_fill(white_pawns, 0, buffer_bool, 0, 64);
white_king  = buffer_fill(white_king, 0, buffer_bool, 0, 64);
[init_script]
Code:
/// @function init_bboards()
/// @arg character_board {array}

var _character_board, char;
_character_board = argument0;

for (var i = 0; i < 64; i++)
{
    char = _character_board[i];
 
    switch (char)
    {
        case "P": buffer_poke(white_pawns, i, buffer_bool, 1); break;
        case "K": buffer_poke(white_king, i, buffer_bool, 1); break;
    }
}
Code:
character_board =
[
    "r", "n", "b", "q", "k", "b", "n", "r",
    "p", "p", "p", "p", "p", "p", "p", "p",
    " ", " ", " ", " ", " ", " ", " ", " ",
    " ", " ", " ", " ", " ", " ", " ", " ",
    " ", " ", " ", " ", " ", " ", " ", " ",
    " ", " ", " ", " ", " ", " ", " ", " ",
    "P", "P", "P", "P", "P", "P", "P", "P", // 48-55
    "R", "N", "B", "Q", "K", "B", "N", "R"
];
When I isolate one by commenting out the other:
white_pawns
0000000000000000000000000000000000000000000000001111111100000000 //Ok
white_king
0000000000000000000000000000000000000000000000000000000000001000 // Ok
When I leave the code as is, both buffers equal:
0000000000000000000000000000000000000000000000001111111100001000 // Why do they merge?
Thanks for reading
 
Last edited:
Top