Page tree
Skip to end of metadata
Go to start of metadata

Introduced in



Description:Returns the index of the first free element (an element that holds no data, or has been set to nil) in the given array. If no free element is available, then the last index+1 is returned.

This function is used for data storage arrays that have their elements deleted by being set to nil (so that pointers to existing elements are not touched). Use this function to recycle those deleted indexes the next time data is added to the array.


Syntax:array call fn_vbs_freeIndex
  • array: Array - The array.
Return Value:Number - Index of first free (nil) element in the given array.


When using functions in VBS versions older than 3.4, certain limitations and requirements should be kept in mind - the main ones being that capitalization of the function name is crucial, and that #include "\vbs2\headers\function_library.hpp" has to be included in every script that utilizes it. More Category VBS Scripting Functions.


// Initialize some data array
_data = [];
{[_data, _x] call fn_vbs_arrayPush} foreach allunits;

// Clear an element out of the array
_data set [_data find player, nil];

// Add new data to the array
// This is placed within the array, where the player used to be
_idx = _data call fn_vbs_freeIndex;
_data set [_idx, guy1];

// Add new data to the array
// The array is extended, and the data is added to the end, since there are no free elements in the array at this time
_idx = _data call fn_vbs_freeIndex;
_data set [_idx, guy2];

Additional Information

See also: