It’s on GitHub!
It’s open source under MIT!
What is Dictionary++?
Well, Dictionary++ is a module that introduces 11 functions to the standard dictionary. Take for instance the limitations of the regular dictionary in Luau.
local foo = {
bar = 1,
car = "red",
orange = {
tasty = true
}
}
print(foo.red)
print(foo["bar"])
Oh well…all you can do is just access it from it in a very 1-dimensional way and if you were to try to simply access “tasty” from “orange” you would be required to type out “foo.orange.tasty” which is fine at first, but what about larger scaled dictionaries? It gets tedious!
This is where Dictionary++ comes into play!
Simply download the module from the website or manually import it from GitHub, and then place the module in ReplicatedStorage(or anywhere else it doesn’t matter) and type out:
local dictionaryPlusPlus = require(game.ReplicatedStorage:WaitForChild("Dictionary++"))
local dictionary = dictionaryPlusPlus({
A = "A",
B = 2,
C = {
D = true,
E = {
F = 1
}
}
})
print(dictionary:get("A")) --prints "A"
Now, why would this be more practical? Isn’t that just more typing? Yes and no. Currently its more typing and if you simply wanted to use a dictionary in this sense you can use a normal dictionary but this is where it gets cool. Let’s get into the first of the 11 functions…
YourDictionary:get(key)
This function would automatically scan every single portion of the dictionary until it finds a match for the key you have provided! 2 things are improved with this!
- it will get and find your key from anywhere in the dictionary making it so much faster to retrieve keys! No more typing “dictionary.C.E.F” simply type out dictionary:get(“F”). Only disadvantage is that currently you can not have an element be named the same as another one and expect dictionary:get(key) to work properly. You can still access it by typing “dictionary.UserContent.blahblahblah” though!
- It will never return nil! Why is this a bonus? Well it means your code won’t break automatically, but don’t worry! It still gives you a warning in the output that it did not find the element you wanted!
And as an added bonus you don’t pass “key” correctly capitalized! It will still find your element. “oRange”, “Orange”, "orange, etc., all work the same!
YourDictionary:set(key, value)
Like the name implies, it sets the key to the value you wanted.
YourDictionary:descendValues()/YourDictionary:descendKeys()
A function similar to GetDescendants!
YourDictionary:add(key, value)/YourDictionary:remove(key)
Of course you can type out “dictionary[key] = value”/“dictionary[key] = nil” so these are more so syntax sugar functions!
YourDictionary:wipe()
Like the name implies it wipes the dictionary clean. No history, no takebacks. Wiped forever.
YourDictionary:convertKeys()/YourDictionary:convertValues()
Now this one is in my opinion the most interesting. It allows you to either convert all the values(or keys) into an array! Take for instance you had a dictionary
local dictionaryPlusPlus = require(game.ReplicatedStorage:WaitForChild("Dictionary++"))
local dictionary = dictionaryPlusPlus({
foo = 1,
bar = false
})
print(dictionary:convertKeys) -prints [1] = "foo" [2] = "bar"
print(dictionary:convertValues) -prints [1] = 1 [2] = false
YourDictionary:count()
Returns the count of all the elements in your dictionary(very useful!)
dictionary:replicateEverything()/dictionary:replicatedCreated()
Another interesting one. So under the hood when you create a dictionary with Dictionary++ it actually looks more like this
local dictionaryPlusPlus = {
UserContent = {
--Your Actual Key/Values
},
--Functions such as get(), set(), replicateEverything(), etc.
}
So when you call YourDictionary:replicateEverything() it returns back EVERYTHING including the default functions. Likewise, YourDictionary:replicateCreated() will only return your custom key/values!
Finally why the name? Why Dictionary++?
Well…it’s referencing the popular programming language C++ which began as just a better version of C. Why the ++? Well because in a lot of programming language(not Lua/Luau) “integer++” is shorthand for “integer += 1” or “integer = integer + 1”. So it’s more like Dictionary + 1!
Woah! That was a lot but I’m finished!
I hope people will benefit from this module!
If you have any questions/concerns just reply to the post and I’ll try to get back ASAP.