returnIndex - sets whether or not the index should be returned
isValueKey - sets whether or not the function should be focused on finding a key match instead of value match
returnUnderIndex - sets whether or not the underIndex should be returned if there is underIndex
(not tested, not completely done logic)
Return description
isFound - contains the status (is a match found or not)
index - contains the index(es) of the given table where the match is found
(only available if returnIndex is true)
underIndex - contains a string of the underIndex(es) (only available if returnUnderIndex is true)
(not tested, don't recommend to use before fixing its logic and test it)
Example 1
local playerVehicles = {
'888DD221',
'000124FD',
'32551AQK'
}
local found = HRLib.table.find(playerVehicles, '888DD221')
if found then
print('The player owns the vehicle')
end
-- The output is:
-- "The player owns the vehicle" (because the value '888DD221' is found in the table)
Example 2
local playerVehicles = {
futo = {
plate = '888DD221'
},
asbo = {
plate = '000124FD'
}
}
local found = HRLib.table.find(playerVehicles, 'futo', nil, true)
if found then
print('The player owns a vehicle with model futo')
end
-- It will print it because a value with key 'futo' is found in the table
-- But for that purpose we use the parameter isValueKey to focus the function
-- on seaching for a key match with the given value
Example 3
local playerVehicles = {
['888DD221'] = {
model = 'futo'
},
['000124FD'] = {
model = 'asbo'
},
['32551AQK'] = {
model = 'futo'
}
}
local found, index = HRLib.table.find(playerVehicles, { model = 'futo' }, true)
if found then
if type(index) == 'table' then
print('The player has more than one vehicle with model futo in its garage')
else
print('The player has only one vehicle with model futo in its garage')
end
end
-- It will print "The player has more than one vehicle with model futo in its garage"
-- because more than one value in the table with underTable's value model is found as futo
table.deepclone
Function to make a deepclone of a table so its changes won't change the main one
function HRLib.table.deepclone(tbl: table): table
Parameters description
tbl - the table to make the deepclone of
cloneStateBag
Function to clone a state bag so you can't lose its value even after it's removed
function HRLib.table.closeStateBag(bagName: string): any[]|false
Parameters description
bagName - the state bag name to clone
table.compare
Function to compare if all values of two tables are same (like tbl1 == tb2 it works with deepcloned tables, because otherwise they won't match because their table identifiers are different)
function HRLib.table.compare(
tbl1: table,
tbl2: table,
noKeyCompare: boolean?
): boolean
Parameters description
tbl1 - the first table for the match
tbl2 - the second table for the match
noKeyCompare - sets whether or not the function should compare and with keys or not
(true to compare tables only with their values, false to compare keys too)
table.getKeys
Function to get a table's keys in an array of strings or multiple values
function HRLib.table.getKeys(tbl: table, isArray: boolean?): ...|string[]?
Parameters description
tbl - the table to get the keys of
isArray - sets whether or not the return value must be in array format or not