Readarrayfromfile: Difference between revisions

From EDukeWiki
Jump to navigation Jump to search
Created page with ''''readarrayfromfile''' <array name> <quote number> Reads a file into a gamearray; the quote contains file name. Each array element will contain 4 bytes of f...'
 
Improved wording
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
'''readarrayfromfile''' <array name> <quote number>
'''readarrayfromfile''' <array name> <quote number>


Reads a file into a [[gamearray]]; the [[definequote|quote]] contains file name. Each array element will contain 4 bytes of file 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 the file's content in sequence. The file is expected to have previously been saved with [[writearraytofile]].
 
Note that this command implicitly resizes the gamearray to have exactly as many entries as required to store the file's content. Therefore, after executing this command, the size of the array may have grown or shrunk, depending on the file that was 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''):
Line 9: Line 11:
  gamevar oct // Byte to select
  gamevar oct // Byte to select
  gamevar ret // Value to return
  gamevar ret // Value to return
redefinequote 256 MYFILE.BIN
readarrayfromfile ARRAY[idx] 256
   
   
  setvarvar idx ofs  shiftvarr idx 2
  setvarvar idx ofs  shiftvarr idx 2
Line 16: Line 21:
  ifvarand oct 1  shiftvarr ret 8
  ifvarand oct 1  shiftvarr ret 8
  andvar ret 255
  andvar ret 255
[[Category:EDuke32 specific commands]]
[[Category:Gamearray manipulation]]

Latest revision as of 04:41, 23 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 the file's content in sequence. The file is expected to have previously been saved with writearraytofile.

Note that this command implicitly resizes the gamearray to have exactly as many entries as required to store the file's content. Therefore, after executing this command, the size of the array may have grown or shrunk, depending on the file that was 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