File.store16

Stores an integer as 16 bits in the file. Note: The value should lie in the interval $(D 0, 2^16 - 1). Any other value will overflow and wrap around. To store a signed integer, use store64 or store a signed integer from the interval $(D -2^15, 2^15 - 1) (i.e. keeping one bit for the signedness) and compute its sign manually when reading. For example:

More...
struct File
@nogc nothrow
void
store16
(
in long value
)

Detailed Description

const MAX_15B = 1 << 15 const MAX_16B = 1 << 16

func unsigned16_to_signed(unsigned): return (unsigned + MAX_15B) % MAX_16B - MAX_15B

func _ready(): var f = File.new() f.open("user://file.dat", File.WRITE_READ) f.store_16(-42) # This wraps around and stores 65494 (2^16 - 42). f.store_16(121) # In bounds, will store 121. f.seek(0) # Go back to start to read the stored value. var read1 = f.get_16() # 65494 var read2 = f.get_16() # 121 var converted1 = unsigned16_to_signed(read1) # -42 var converted2 = unsigned16_to_signed(read2) # 121

Meta