This module will run a loop and append any IDs it finds to a table corresponding to the asset type.
Module link: Asset Dictionary
Documentation: Asset Dictionary Documentation
GitHub: bloodbonnieking/Roblox-Asset-Dictionary
Updates
V1.1:
- Added different tables for every asset
- Fixed the 2nd argument not doing anything
- Changed the elseifs to cases (table)
- Added some exceptions and errors
V1.2:
- Fixed a coding oversight that would only sort AssetDictionary, DecalDictionary and TextureDictionary
- Added a new optional boolean “Reverse”. Read more in the documentation.
V1.3:
- Added pants and shirt support
V1.4:
- Fixed supported assets getting skipped over for “not being supported”
- Switched to numeric for loop to hopefully speed stuff up
- Switched to using typeof() for exceptions
V1.5:
- Added a few memory related functions (read more in the documentation)
- Changed the AssetDictionary table to GeneralDictionary, and finally deprecated it.
(REMOVED COMPLETELY IN V1.6)
V1.6:
- Removed GeneralDictionary (it was useless and it made the script unreadable)
- Added type notations (tried to add type notations before in a few unreleased versions because I didn’t know that ? makes it optional)
- Removed nil checks
- Made errors tell you the argument name instead
- Added a new argument, read more in the documentation
V1.7:
- Moved documentation (and made it better)
- Moved animation dictionary to above image labels, this does not affect anything and is merely tidying up the code a bit
- Changed . to : for functions for slight consistency
- Video support
- ClearTable now needs the asset type name to avoid accidental clearing of non-related tables
- Errors are now level 2 errors
- Added a print argument for debugging
V1.8:
- Cleaned up the code, got rid of useless things and improved it a bit
- Moved dictionaries into ModuleDictionary.Dictionaries. This isn’t a big change, but possibly a tedious one.
- Got rid of “temporary tables” which were the tables that weren’t share across scripts.
- Created a new argument, ClearTables which will clear all of the tables before appending the ids (default is true)
- Removed some useless exceptions
- Script uses native Luau now (from my testing, it used to take a solid second without native and now it takes like less than half a second) (read more here: Luau Native Code Generation Preview [Studio Beta])
- Made ClearTable WAY more compact
- ClearTable now accepts strings with “Dictionary”, not just without
V1.8.1 (not wasting a version number) - The GetDictionary scope no longer ends before the return (that wasn’t intentional)
- Print will now print a benchmark (note: the time starts as soon as the function is called and the print happens at the end, which means other if statements may change the result.)
V1.9 - Added support for particle emitters
- that’s it
What’s supported:
- Decals
- Textures
- Sounds
- Meshes
- Animations
- Image labels
- Image buttons
- Video frames
- Shirts
- Pants
- Particle emitters
Here is the code if you don’t want to open it in a place:
--!native
local ModuleDictionary = {}
ModuleDictionary.Dictionaries = {
GeneralDictionary = {};
DecalDictionary = {};
TextureDictionary = {};
SoundDictionary = {};
MeshDictionary = {};
AnimationDictionary = {};
VideoDictionary = {};
ImageLabelDictionary = {};
ImageButtonDictionary = {};
ShirtDictionary = {};
PantsDictionary = {};
ParticleDictionary = {}
}
local Dictionaries = ModuleDictionary.Dictionaries
--//main functions
local function AddToTable(Target, Print)
local Start = os.clock()
for index = 1, #Target do
local Cases = {
["Decal"] = function ()
table.insert(Dictionaries.DecalDictionary, Target[index].Texture)
table.insert(Dictionaries.GeneralDictionary, Target[index].Texture)
end,
["Texture"] = function ()
table.insert(Dictionaries.TextureDictionary, Target[index].Texture)
table.insert(Dictionaries.GeneralDictionary, Target[index].Texture)
end,
["Sound"] = function ()
table.insert(Dictionaries.TextureDictionary, Target[index].SoundId)
table.insert(Dictionaries.GeneralDictionary, Target[index].SoundId)
end,
["Mesh"] = function ()
table.insert(Dictionaries.MeshDictionary, Target[index].MeshId)
table.insert(Dictionaries.GeneralDictionary, Target[index].MeshId)
end,
["Animation"] = function ()
table.insert(Dictionaries.AnimationDictionary, Target[index].AnimationId)
table.insert(Dictionaries.GeneralDictionary, Target[index].AnimationId)
end,
["VideoFrame"] = function ()
table.insert(Dictionaries.VideoDictionary, Target[index].Video)
table.insert(Dictionaries.GeneralDictionary, Target[index].Video)
end,
["ImageLabel"] = function ()
table.insert(Dictionaries.ImageLabelDictionary, Target[index].Image)
table.insert(Dictionaries.GeneralDictionary, Target[index].Image)
end,
["ImageButton"] = function ()
table.insert(Dictionaries.ImageButtonDictionary, Target[index].Image)
table.insert(Dictionaries.GeneralDictionary, Target[index].Image)
end,
["Shirt"] = function ()
table.insert(Dictionaries.ShirtDictionary, Target[index].ShirtTemplate)
table.insert(Dictionaries.GeneralDictionary, Target[index].ShirtTemplate)
end,
["Pants"] = function ()
table.insert(Dictionaries.PantsDictionary, Target[index].PantsTemplate)
table.insert(Dictionaries.GeneralDictionary, Target[index].PantsTemplate)
end,
["ParticleEmitter"] = function ()
table.insert(Dictionaries.ParticleDictionary, Target[index].Texture)
table.insert(Dictionaries.GeneralDictionary, Target[index].Texture)
end,
}
if Print then
print(`Name: {Target[index]} ClassName: {Target[index].ClassName}`)
end
local success, err = pcall(function()
Cases[Target[index].ClassName]()
end)
if not success and Print then
warn("Instance is not supported. Expected a downloadable or supported asset, got "..tostring(Target[index].ClassName))
end
end
local End = os.clock()
if Print then
print(`For loop took: {End - Start}`)
end
end
function ModuleDictionary:GetDictionary(Target: Instance, Descendants: boolean?, ClearTables: boolean?, Sort: boolean?, Reverse: boolean?, DeleteTarget: boolean?, Print: boolean?)
local StartTime = os.clock()
if typeof(Target) ~= "Instance" then error(`GetDictionary expects Target to be an instance, got {tostring(Target)}`) end
if typeof(Descendants) ~= "boolean" then Descendants = false end
if typeof(ClearTables) ~= "boolean" then ClearTables = true end
if typeof(DeleteTarget) ~= "boolean" then DeleteTarget = false end
if typeof(Sort) ~= "boolean" then Sort = true end
if typeof(Reverse) ~= "boolean" then Reverse = true end
if typeof(Print) ~= "boolean" then Print = false end
if ClearTables == true then
for _, tables in pairs(Dictionaries) do
table.clear(tables)
end
end
if Descendants == false then
AddToTable(Target:GetChildren(), Print)
elseif Descendants == true then
AddToTable(Target:GetDescendants(), Print)
end
local function ReverseTable(ID1, ID2)
pcall(function()
--print(ID1, ID2)
return ID1 > ID2
end)
end
if Reverse == false and Sort == true then
for _, tables in pairs(Dictionaries) do
table.sort(tables)
end
elseif Reverse == true and Sort == true then
for _, tables in pairs(Dictionaries) do
print(tables)
table.sort(tables, ReverseTable)
end
end
if DeleteTarget == true then
Target:Destroy()
end
if Print == true then
print("General:", Dictionaries.GeneralDictionary)
print("Decals:", Dictionaries.DecalDictionary)
print("Textures:", Dictionaries.TextureDictionary)
print("Sounds:", Dictionaries. SoundDictionary)
print("Meshes:", Dictionaries.MeshDictionary)
print("Animations:", Dictionaries.AnimationDictionary)
print("Videos:", Dictionaries.VideoDictionary)
print("Image Labels:", Dictionaries.ImageLabelDictionary)
print("Image Buttons:", Dictionaries.ImageButtonDictionary)
print("Shirts:", Dictionaries.ShirtDictionary)
print("Pants:", Dictionaries.PantsDictionary)
print("Particles:", Dictionaries.ParticleDictionary)
local EndTime = os.clock()
print(`Took: {EndTime - StartTime}`)
end
end
--//memory freeing functions
function ModuleDictionary:ClearTable(Table: string)
if typeof(Table) == "string" then
local success, err = pcall(function()
print(Table)
if Table:find("Dictionary") then
table.clear(Dictionaries[Table])
else
table.clear(Dictionaries[Table.. "Dictionary"])
end
end)
if not success then
error("ClearTable expects the string to be a supported asset, got "..Table, 2)
end
end
end
function ModuleDictionary:ClearAllTables() --//no arguments needed, and will only clear asset dictionary tables.
for _, tables in pairs (Dictionaries) do
table.clear(tables)
end
end
task.spawn(function()
while task.wait(1) do
print(Dictionaries)
end
end)
return ModuleDictionary