Shared
table.focusedArray
Function to filter indexes in an array of tables with common value(s)
function HRLib.table.focusedArray(
array: table<string, any>[],
focus: table<string, any>,
cb: fun(i: integer, curr: any)?
)Parameters description
array- the array to filter the indexes fromfocus- the table that includes the filter valuescb- the function that is being triggered when a match is found
Example
local array = {
{
ownerName = 'player_1',
cashBalance = 2500
},
{
ownerName = 'player_2',
cashBalance = 6000
},
{
ownerName = 'player_1',
cashBalance = 1050
}
}
HRLib.table.focusedArray(array, { ownerName = 'player_1' }, function(_, curr)
print(curr.cashBalance)
end) -- the output is two printed values, 2500 and 1050table.focusedHash
Function to filter keys in a hash table of arrays with common values in the arrays
Parameters description
hash- the hash table to filter the keys fromfocus- the table that includes the filter values or any value to find match with the values from the arraycb- the function that is being triggered when a match is found
Example 1
Example 2
table.getHashLength
Function to get the number of keys with values in a hash table (if in any scenario you're gonna need it)
Parameters description
hash- the hash table to get the length of
table.find
Function to values in any table and different kinds of value
Parameters description
tbl- the table to search the value invalue- the value to search a match withreturnIndex- sets whether or not the index should be returnedisValueKey- sets whether or not the function should be focused on finding a key match instead of value matchreturnUnderIndex- 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 ifreturnIndexis 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
Example 2
Example 3
table.deepclone
Function to make a deepclone of a table so its changes won't change the main one
Parameters description
tbl- the table to make the deepclone ofdontCopyMetatable- sets whether or not if a metatable exists of the given table, it should be copied
cloneStateBag
Function to clone a state bag so you can't lose its value even after it's removed
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)
Parameters description
tbl1- the first table for the matchtbl2- the second table for the matchnoKeyCompare- 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
Parameters description
tbl- the table to get the keys ofisArray- sets whether or not the return value must be in array format or not
table.toString
Function to convert lua tables into visible strings that can be loaded via load function, (helpful for .lua metadata files)
Parameters description
tbl- the target table to convert to stringindent- sets whether or not the string should include new rows, tabs and so forth just like the lua tables usually look when they're being created or the string should include the table on one row.rowsSpace- the number of new rows between values declaration (by default it's1)
Last updated