Legacy GM Buffer write [SOLVED]


Barack Pálinka

How do you decide when to use buffer_u or buffer_s?
And how do you decide when to use buffer_u8 or buffer_u16 or buffer_u32?
Last edited by a moderator:


https://docs.yoyogames.com/source/dadiospice/002_reference/buffers/using buffers.html

The documentation has plenty of information about buffers, I would recommend checking it out, its pretty self explanatory.
buffer_u8, for an example, holds a value from 0 to 255. Should the value you want to send not have any chance of being different than that, use buffer_u8. If you want to send coordinates in the room, for an example, you should use buffer_f32, which can hold a floating point (not round), positive or negative number from -16777216 to 16777216. Its pretty simple.


The different buffer types correspond to data types you normally encounter when programming at a bit lower level. Those data types can only represent certain ranges of numbers. Generally speaking you want to choose the smallest data type that can accommodate the range of values you might need to put into it.

Take "buffer_u8" for example. That refers to an 8 bit, unsigned integer. With 8 bit unsigned, the smallest number you can represent is 00000000 (0), and the largest number you can represent is 11111111 (255). With 8 bit signed (buffer_s8), the smallest number you can represent is 10000001 ( -128 in 2's complement representation), and the largest number you can represent is 01111111 (+127).

Similar story for the other integer types, like it says in the manual, buffer_u16 can represent a number in the range 0->65535 and buffer_u16 can represent a number in the range -32768->+32767. So on for the larger integers.

Floating point numbers (buffer_f32, buffer_f64) work much differently at a bit level, but in general can represent a wider range of values, trading it off for a loss of precision. You can read about them here: https://en.wikipedia.org/wiki/Single-precision_floating-point_format (buffer_f32) https://en.wikipedia.org/wiki/Double-precision_floating-point_format (buffer_f64).

If for example, you had a room that was 640x480 in size and you wanted to store some object's x and y coordinate in a buffer, you could use buffer_u16 if you were sure the x and y coordinates would never be negative. If they might become negative, you could still use buffer_s16 and have plenty of room to spare.

Barack Pálinka

Thanks for the answers,one more question,does buffer_u8 = 1 byte?