Click or drag to resize

FileStore16 Method

Stores an integer as 16 bits in the file.

Note: The value should lie in the interval [0, 2^16 - 1]. Any other value will overflow and wrap around.

To store a signed integer, use Store64(UInt64) or store a signed integer from the interval [-2^15, 2^15 - 1] (i.e. keeping one bit for the signedness) and compute its sign manually when reading. For example:

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

Namespace:  Godot
Assembly:  GodotSharp (in GodotSharp.dll) Version: 1.0.0
Syntax
C#
public void Store16(
	ushort value
)

Parameters

value
Type: SystemUInt16

[Missing <param name="value"/> documentation for "M:Godot.File.Store16(System.UInt16)"]

See Also