Dictionary Key Question

Hi. Currently using a Dictionary to save DS2 prison arrests.

My dictionary looks something like this:

{
Arrest = {“ArrestingOfficer”,“Reason”,Duration},
Arrest = {“anotherOfficer”, “anotherReason”,Duration},
}
I’m unsure if this is a good way, seeming as dictionarys use keys to access, so in order to write into this dictionary, I think it’d mess up because there’s already an arrest key? Could someone explain this, and how I could write into, or create a more efficient way to do this?

Each key must be unique, if you want to list things by number use array.

{
value1,
value2,
value3,
}

I want dictionary specifically, could I instead find the number of Arrests, and append a number to the new one

Example:
{
Arrest1 = blabla
Arrest2 = blabla
}

You can do whatever you want as long as you follow lua syntax.

Dictionaries must have unique keys, otherwise you will overwrite an existing key.

Arrays don’t use keys they use a numbered list of items. You can access each index by doing array[index_number]

Do arrays accept tables as a value?

{
{val1 = “No”, val2 = “Yes”},
{val1 = “Hmph.”,val2 = “Ahh…”}
}

When saving a key which already exists in a dictionary(Arrest) it will overwrite the old one. Instead you could store an array inside the dictionary key “Arrests” containing each arrest:

local data = {
	Arrests = {
		arrest1,
		arrest2,
		arrest3,
		--etc.
	}
}

But the arrests itself are a dictionary,

Can you store a dictionary inside an array?
{{coins = 100, money = 2}, {coins = 50, money = 20}}

1 Like

in lua table is table

Any data type can be value and most things can be key (string, number, userdata even function)

If you are saving data to datastore however keys must be string or number and value must be table, string, number, boolean, or nil.