LumpRead: Difference between revisions
(Update formatting and specifications on failure) |
DrinkyBird (talk | contribs) (Added to Category: ACS functions) Tag: Source edit |
||
(2 intermediate revisions by one other user not shown) | |||
Line 6: | Line 6: | ||
By default, the ''type'' returned is an unsigned 8-bit integer. | By default, the ''type'' returned is an unsigned 8-bit integer. | ||
===Parameters=== | ===Parameters=== | ||
*''lump'': The lump index as returned from | *''lump'': The lump index as returned from [[LumpOpen]]. | ||
*''pos'': The byte position in the lump to read from. | *''pos'': The byte position in the lump to read from. | ||
*''type'': The type of integer that should be returned. | *''type'': The type of integer that should be returned. | ||
Line 13: | Line 13: | ||
**<code>LUMP_READ_SHORT</code>: Signed 16-bit integer. | **<code>LUMP_READ_SHORT</code>: Signed 16-bit integer. | ||
**<code>LUMP_READ_USHORT</code>: Unsigned 16-bit integer. | **<code>LUMP_READ_USHORT</code>: Unsigned 16-bit integer. | ||
** <code>LUMP_READ_INT</code>: Signed 32-bit integer. | **<code>LUMP_READ_INT</code>: Signed 32-bit integer. | ||
**<code>LUMP_READ_FLOAT</code>: Signed 32-bit float converted to a fixed-point. | **<code>LUMP_READ_FLOAT</code>: Signed 32-bit float converted to a fixed-point. | ||
===Return value === | ===Return value=== | ||
Returns the integer that was read. | 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. | 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 | Also returns 0 when called on a lump that was not opened with [[LumpOpen]], alongside a console message. | ||
==Examples== | ==Examples== | ||
{{ | <syntaxhighlight lang="js" line="1"> | ||
// 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); | |||
} | |||
} | |||
</syntaxhighlight> | |||
==See also== | |||
*[[LumpRead]] | |||
*[[LumpReadArray]] | |||
*[[LumpReadString]] | |||
*[[LumpGetInfo]] | |||
*[[LumpClose]] | |||
[[Category: ACS functions]] |
Latest revision as of 15:59, 25 January 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 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);
}
}