LumpGetInfo: Difference between revisions
Add example
(Update specifications on failure) |
(Add example) |
||
Line 6: | Line 6: | ||
==Usage== | ==Usage== | ||
Returns information of the lump, based on ''info''. | Returns information of the lump, based on ''info''. | ||
For clarification, this function does not require the lump to be open, but [[LumpOpen]] could be used to fetch the lump's index. | |||
===Parameters=== | ===Parameters=== | ||
*''lump'': The lump index as returned from | *''lump'': The lump index as returned from [[LumpOpen]]. Note that an index higher than the total number of lumps can crash the game. | ||
*''info'': The type of information to return. | *''info'': The type of information to return. | ||
**<code>LUMP_INFO_SIZE</code>: The buffer size of the lump. | **<code>LUMP_INFO_SIZE</code>: The buffer size of the lump. | ||
**<code>LUMP_INFO_NAME</code>: The full name (including path) of the lump. | **<code>LUMP_INFO_NAME</code>: The full name (including path) of the lump. | ||
Line 21: | Line 23: | ||
==Examples== | ==Examples== | ||
{{ | <syntaxhighlight lang="js" line="1"> | ||
// This script finds the first instance of the "MYLUMP" lump and proceeds to log the 100 lumps above it. | |||
// "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 = LumpOpen("MYLUMP", 0); | |||
// The initial lump was not found. | |||
if (startIndex == -1) { | |||
terminate; | |||
} | |||
// Make sure to close the lump again to free the handle. | |||
LumpClose(startIndex); | |||
int remainingLumps = 100; | |||
while(remainingLumps > 0 && startIndex >= 0) | |||
{ | |||
int size = LumpGetInfo(startIndex, LUMP_INFO_SIZE); | |||
str name = LumpGetInfo(startIndex, LUMP_INFO_NAME); | |||
Log(s:"The next lump is ", s:name , s:" with size ", d:size, s:"."); | |||
remainingLumps--; | |||
startIndex--; | |||
} | |||
} | |||
</syntaxhighlight> | |||
==See also== | |||
*[[LumpOpen]] | |||
*[[LumpRead]] | |||
*[[LumpReadArray]] | |||
*[[LumpReadString]] | |||
*[[LumpClose]] | |||
[[Category:ACS functions]] | [[Category:ACS functions]] |