LumpRead

From Zandronum Wiki
Revision as of 15:59, 25 January 2024 by DrinkyBird (talk | contribs) (Added to Category: ACS functions)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 LumpRead (int lump, int pos [, int type]) (development version 3.2-alpha and above only)

Usage

Reads an integer. The value of this integer is based on the type passed.

By default, the type returned is an unsigned 8-bit integer.

Parameters

  • lump: The lump index as returned from LumpOpen.
  • pos: The byte position in the lump to read from.
  • type: The type of integer that should be returned.
    • LUMP_READ_BYTE: Signed 8-bit integer.
    • LUMP_READ_UBYTE: Unsigned 8-bit integer.
    • LUMP_READ_SHORT: Signed 16-bit integer.
    • LUMP_READ_USHORT: Unsigned 16-bit integer.
    • LUMP_READ_INT: Signed 32-bit integer.
    • LUMP_READ_FLOAT: Signed 32-bit float converted to a fixed-point.

Return value

Returns the integer that was read.

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

Also returns 0 when called on a lump that was not opened with LumpOpen, alongside a console message.

Examples

// This script opens all lumps with the name "MYLUMP" and reads the integer that exists on position zero.
// "MYLUMP" is not a real lump, and you should replace it with a lump that does exist.
// `CLIENTSIDE` is optional.
Script 1 OPEN CLIENTSIDE
{
	int startIndex = -1;
	
	while(true)
	{
		startIndex = LumpOpen("MYLUMP", startIndex + 1);

		// The next lump was not found.
		if (startIndex == -1) {
			break;
		}
		
		// Read the integer that exists in the lump at position zero.
		int value = LumpRead(startIndex, LUMP_READ_INT, 0);
		Log(s:"The integer that was read is ", d:value, s:".");

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

See also