Ever since the new introduction of the new buffer type I’ve been experimenting with it, but I’ve ran into a problem (or what could be my own stupidity lol). Here is some code:
local b = buffer.create(10) --
buffer.writei16(b, 0, 100)
print(buffer.readi16(b, 0))
This piece of code expectedly prints 10 (which it does), but this is not where the problem occurs. It is when I add another value at a different offset where things start getting confusing for me:
local b = buffer.create(10)
buffer.writei16(b, 0, 100)
buffer.writei16(b, 1, 101)
print(buffer.readi16(b, 0)) --25956 ???
print(buffer.readi16(b, 1)) --101
For whatever reason, when I try to read the value at 0, it returns some confusing number. In this case it returns 25956. The weird thing though is when I change the offset from 1 to 2 for the second value, the code works normally again. From what it seems I have to keep atleast one space free between values I want to write to keep them from “corrupting”, “changing”, or whatever you would call this occurance.
local b = buffer.create(10)
buffer.writei16(b, 0, 100)
buffer.writei16(b, 2, 101)
print(buffer.readi16(b, 0)) --100
print(buffer.readi16(b, 1)) --101
-- Problem solved?
Edit: I’ve also decided to test with writei8/readi8 and it seems to work perfectly fine
Edit 2: It for some reason also happens for f32 but this time you need 3 gaps between two values for some reason. I have no idea why this is happening, perhaps my testing could be just bad.