I have the dictionary:
Ranks = { first = { Salary = 200}, second = {Salary = 275}, third = {Salary = 350}, fourth = {Salary = 500}, fifth = {Salary = 1000}, },
And I want to set a table in the datastore as that table but it won't show up in the datastore plugin for my data:
PlayerSesStats[player.UserId].JobStats.Rank = job.Ranks[1]
Also when I do print(~~~location of the dictionary~~~.Ranks[1])
it outputs nil. Help?
To index a dictionary with a string key, put the key in square brackets after the dictionary (this works woth any key):
print(Ranks["first"])
Also FYI, you can iterate through a dictionary, and the index becomes the key and the value is the table:
for Index,Value in pairs(Ranks) do print(Index,Value) end
Each iteration, Index will be the keys (the words first, second, third, etc.) and the tables associated with them.
If you want to index it by a number, you should make it an array (integer keys) rather than a dictionary. This cn be achieved by simply removing the keys:
Ranks = { { Salary = 200}, {Salary = 275}, {Salary = 350}, {Salary = 500}, {Salary = 1000} }
Then, you can simply go:
print(Ranks[2].Salary)
which would print 275.
you are using string keys, and 1 is not equal to "first", it would makes thing (especially future casees) WAY less complicated, also number keys dont need to be made clear, as long as they are defined in propper order
Ranks = { {Salary = 200}, {Salary = 275}, {Salary = 350}, {Salary = 500}, {Salary = 1000}, },