此函数可用于将数据写入先前创建的缓冲区。您写入的数据必须与此函数的 "type" 参数一致,这意味着您不能尝试将字符串写入为无符号 16 位整数。
该函数会将您的给定值写入缓冲区的 当前查找位置 。
以下常量可用于定义数据类型:
常量 | 描述 | 返回的数据类型 |
---|---|---|
buffer_u8 | An unsigned, 8bit integer. This is a positive value from 0 to 255. | int32 |
buffer_s8 | A signed, 8bit integer. This can be a positive or negative value from -128 to 127 (0 is classed as positive). | int32 |
buffer_u16 | An unsigned, 16bit integer. This is a positive value from 0 - 65,535. | int32 |
buffer_s16 | A signed, 16bit integer. This can be a positive or negative value from -32,768 to 32,767 (0 is classed as positive). | int32 |
buffer_u32 | An unsigned, 32bit integer. This is a positive value from 0 to 4,294,967,295. | int64 |
buffer_s32 | A signed, 32bit integer. This can be a positive or negative value from -2,147,483,648 to 2,147,483,647 (0 is classed as positive). | int32 |
buffer_u64 | An unsigned 64bit integer. This is a positive value from 0 to 18,446,744,073,709,551,615. | int64 |
buffer_f16 | A 16bit float. This can be a positive or negative value within the range of +/- 65504. | number (real) |
buffer_f32 | A 32bit float. This can be a positive or negative value within the range of +/-16777216. | number (real) |
buffer_f64 | A 64bit float. | number (real) |
buffer_bool | A boolean value, can only be either 1 or 0 (true or false). It is stored in a single byte (8bit) | int32 |
buffer_string | A string of any size, including a final null terminating character | string |
buffer_text | A string of any size, without the final null terminating character | string |
如果成功,函数将返回0;如果失败,则返回-1。
buffer_write(buffer, type, value);
参数 | 类型 | 描述 |
---|---|---|
buffer | Buffer | 要写入的缓冲区。 |
type | Real | 要写入缓冲区的数据类型 (请参阅上面的常量列表)。 |
value | Real | 要写入的数据。 |
Real (0 if success, or -1 if it fails)
buffer_seek(buff, buffer_seek_start, 0);
buffer_write(buff, buffer_s16, 0);
buffer_write(buff, buffer_s16, x);
buffer_write(buff, buffer_s16, y);
上面的代码找到存储在变量 buff 中的缓冲区的开头,然后向其中写入一系列带符号的 16 位整数值。