LumpGetInfo: Difference between revisions

Add example
(Created page with "{{ACSWarning}} {{DevfeatureWarning|version=3.2|type=an ACS function}} mixed '''LumpGetInfo''' (int ''lump'', int ''info'') {{Devfeature|3.2|alpha}} ==Usage== Returns information of the lump, based on ''info''. ===Parameters=== *''lump'': The lump index as returned from <tt>LumpOpen</tt>. *''info'': The type of information to return. **<code>LUMP_INFO_SIZE</code>: The buffer size of the lump. **<code>LUMP_INFO_NAME</code>: The full name (including path) of the...")
 
(Add example)
 
(One intermediate revision by the same user not shown)
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 <tt>[[LumpOpen]]</tt>.
*''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 18: Line 20:
If ''info'' is <code>LUMP_INFO_NAME</code>, returns a string containing the lump's full name.
If ''info'' is <code>LUMP_INFO_NAME</code>, returns a string containing the lump's full name.


Returns 0 on invalid input, or when attempting to read a lump that has not yet been opened with <tt>[[LumpOpen]]</tt>.
Returns 0 on invalid input, alongside a console message.


==Examples==
==Examples==
{{noexamples}}
<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]]