Readarrayfromfile: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
No edit summary
Add note that mentions implicit array resizing.
Line 2: Line 2:


Reads a file into a [[gamearray]]; the [[definequote|quote]] contains the file name. Each array element will contain 4 bytes of file's content. The file is to be previously saved with [[writearraytofile]].
Reads a file into a [[gamearray]]; the [[definequote|quote]] contains the file name. Each array element will contain 4 bytes of file's content. The file is to be previously saved with [[writearraytofile]].
Note that this command implicitly resizes the gamearray to exactly equal the size of the file, even if the gamearray was previously defined to be larger than the file that is loaded.


Here's an example of how an array can be accessed byte-wise (in case you are using files which were not created by ''writearraytofile''):
Here's an example of how an array can be accessed byte-wise (in case you are using files which were not created by ''writearraytofile''):

Revision as of 03:52, 22 January 2020

readarrayfromfile <array name> <quote number>

Reads a file into a gamearray; the quote contains the file name. Each array element will contain 4 bytes of file's content. The file is to be previously saved with writearraytofile.

Note that this command implicitly resizes the gamearray to exactly equal the size of the file, even if the gamearray was previously defined to be larger than the file that is loaded.

Here's an example of how an array can be accessed byte-wise (in case you are using files which were not created by writearraytofile):

gamevar ofs // Byte address
gamevar idx // Array index
gamevar oct // Byte to select
gamevar ret // Value to return

redefinequote 256 MYFILE.BIN
readarrayfromfile ARRAY[idx] 256

setvarvar idx ofs  shiftvarr idx 2
setvarvar oct ofs  andvar oct 3 // DWORD to BYTE ptr
setvarvar ret ARRAY[idx]
ifvarand oct 2  shiftvarr ret 16
ifvarand oct 1  shiftvarr ret 8
andvar ret 255