How to create a value inside another value in an array to turn it into a dictionary

Hey there i was working on a project and i needed some help with tables and how to turn them into dictionaries.

Lets say this is my array

local myTable = {
     val1,
     val2,
     val3}

This is currently an array however i want the values to have similar to instances like children. Basically a dictionary

What i tried doing is something like this

myTable[index]['Value inside of value'] = val11

essentially trying to create a value inside lets say val1

whenever i try doing this it tells me trying to index string.

Am i missing some simple functions or algorithms?

Any help would be great

I’m sorry but i don’t quite understand your post, can you explain more what you’re trying to do and what’s the problem?

Basically how do i attach a value to a value inside the table basically

before

local myTable = {
    val1,
    val2
}

After

local myTable = {
        val1 = 'Example 1'
        val2 = 'Example 2'

This done through a script and i dont need the loop part i just want to know how to apply the values to the table.

Thank you

To set a value of a dictionary you would normally do this.

myTable[val1] = "Example 1"

local myArray = {"foo", "bar", "baz"}

local myDictionary = {}

for key, value in pairs(myArray) do
    myDictionary[value] = true
end

The code above creates a dictionary from an array. The dictionary will have keys for each value in the array, and the values will all be set to true.

oh right i got confused when indexing and i did it the other way round.

Thanks anyways

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.