LumpReadArray: Difference between revisions

(Documented LumpReadArray)
Tag: Source edit
 
(Fix example)
Tag: Source edit
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{ACSWarning}}{{DevfeatureWarning|version=3.2|type=an [[ACS]] function}}
{{ACSWarning}}{{DevfeatureWarning|version=3.2|type=an [[ACS]] function}}
int '''LumpReadArray''' (int ''lump'', int ''pos'' array ''array'', int ''arrayPos''[, int ''length'']) {{Devfeature|3.2|alpha}}
int '''LumpReadArray''' (int ''lump'', int ''pos'', array ''array'', int ''arrayPos''[, int ''length'']) {{Devfeature|3.2|alpha}}
==Usage==
==Usage==
Reads bytes from the lump into the given array.
Reads bytes from the lump into the given array.
Line 22: Line 22:
int handle = LumpOpen("MYLUMP");
int handle = LumpOpen("MYLUMP");


     // The next lump was not found.
     // The lump was not found.
     if (startIndex == -1) {
     if (handle == -1) {
         break;
         terminate;
     }
     }


Line 49: Line 49:
*[[LumpGetInfo]]
*[[LumpGetInfo]]
*[[LumpClose]]
*[[LumpClose]]
[[Category: ACS functions]]

Latest revision as of 14:36, 4 May 2024

This article documents a Zandronum-specific ACS feature which may not be supported by ZDoom and its other child ports.
This article documents an ACS function which is only available in development builds of Zandronum 3.2 and newer.

int LumpReadArray (int lump, int pos, array array, int arrayPos[, int length]) (development version 3.2-alpha and above only)

Usage

Reads bytes from the lump into the given array.

Parameters

  • lump: The lump index as returned from LumpOpen.
  • pos: The byte position in the lump to read from.
  • array: The array data will be read into.
  • arrayPos: Position within the array data will start being read into.
  • length: Number of bytes to be read. By default this will be the size of the lump.

Return value

Returns the number of bytes read.

Returns 0 if the lump passed is invalid, alongside a console message.

Examples

// This example opens a lump named "MYLUMP", reads the first four bytes, and tests if they equal the magic header "BLAH".
Script 1 OPEN CLIENTSIDE {
	int handle = LumpOpen("MYLUMP");

    // The lump was not found.
    if (handle == -1) {
        terminate;
    }

    int magic[4];
    // Read 4 bytes from the start of the lump into the start of the array.
    LumpReadArray(handle, 0, magic, 0, 4);

    if (magic[0] == 'B' || magic[1] == 'L' || magic[2] == 'A' || magic[3] == 'H') {
        Print(s: "Lump has a valid magic");
    }
    else {
        Print(s: "Lump has invalid magic");
    }

    // Make sure to close the lump again to free the handle.
    LumpClose(handle);
}

See also