buffer_write

This function can be used to write data to a previously created buffer. The data you write must be in agreement with the "type" argument of this function, meaning that you can't try to write a string as an unsigned 16bit integer, for example.

The function will write your given value at the buffer's current seek position.

The following constants can be used to define the data type:

Buffer Data Type Constant
ConstantDescriptionDatatype Returned
buffer_u8An unsigned, 8bit integer. This is a positive value from 0 to 255.int32
buffer_s8A signed, 8bit integer. This can be a positive or negative value from -128 to 127 (0 is classed as positive).int32
buffer_u16An unsigned, 16bit integer. This is a positive value from 0 - 65,535.int32
buffer_s16A signed, 16bit integer. This can be a positive or negative value from -32,768 to 32,767 (0 is classed as positive).int32
buffer_u32An unsigned, 32bit integer. This is a positive value from 0 to 4,294,967,295.int64
buffer_s32A 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_u64An unsigned 64bit integer. This is a positive value from 0 to 18,446,744,073,709,551,615.int64
buffer_f16A 16bit float. This can be a positive or negative value within the range of +/- 65504.number (real)
buffer_f32A 32bit float. This can be a positive or negative value within the range of +/-16777216.number (real)
buffer_f64A 64bit float.number (real)
buffer_boolA boolean value, can only be either 1 or 0 (true or false). It is stored in a single byte (8bit)int32
buffer_stringA string of any size, including a final null terminating characterstring
buffer_textA string of any size, without the final null terminating characterstring

The function will return 0 if it succeeds or -1 if it fails.

 

Syntax:

buffer_write(buffer, type, value);

ArgumentTypeDescription
bufferBufferThe buffer to write to.
typeRealThe type of data to be written to the buffer (see the list of constants above).
valueRealThe data to write.

 

Returns:

Real (0 if success, or -1 if it fails)

 

Example:

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);

The above code finds the start of the buffer stored in the variable buff then writes a series of signed 16bit integer values to it.