You must be logged in to do that.

FileWriteWord

FileWriteWord
void FileWriteWord(int file, int word)

Documentation

Pass a handle to a file that is opened in write mode, and an integer to be written. Two bytes will be written at the current position within the file, over any data that was previously there, and position will move to the next byte. As only two bytes of the four bytes that make up a verge integer is being written, any numbers bigger than 65535 or less than 0 will NOT be written correctly. Use FileWriteQuad() unless sure the number being written will remain within these bounds.

Verge is effectivly only writing the 16 least significant bits of the passed integer, so performing a (integer & 65535) operation before writing. Numbers outside the range of 0 to 65535 will be written as another number with the range, depending on the value of the two least significant bytes. Note also that the bytes are stored in order of least significant to most significant. In effect what happens is:

FileWriteByte(quad & 255);
FileWriteByte(quad & (255 << 8));

Example Usage

int file = FileOpen("datafile.txt", FILE_WRITE);
FileWriteByte(file, 97); // or $61 or 'a'
FileClose(file);
// Opens/Creats a file and writes one byte to it
// Opened in a hex editor gives '61 00' as value of the byte
// In a text editor it gives the ascii 'a'

int file = FileOpen("datafile.txt", FILE_WRITE);
FileWriteByte(file, 0 - 2);
FileClose(file);
// Negative numbers are not stored properly
// Opened in a hex editor gives 'fe ff' as value of the byte
// -2 in binary: 11111111111111111111111111111110
// Two least significant bytes: 1111111111111110
// Decimal: 65534
Talkback

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.