Help me understand more about empty table

I’ve been learning datastore for a while now and I just want to understand more about empty tables.


here is a picture of a yt tutorial by Suphi Kaner
I’ve been looking on the devforum, yt, google for 4 days now and I still can’t seem to understand how it works!!!
Here are some questions that I want to be answered please:
Did he index the folder.name or child.Name for a key to name the data or did he use it for something else?
Why did he use the name of the folder?
Does it matter if he used a string like “ham” instead of the folder.name?
Did he insert things like the folder.name in a table(dictionary) ?
image
How did he set the child.value by just child.name?
I don’t really understand why he used the name of folders and child and how he did it with a empty table. I know it’s an intermediate question but if anyone is able to explain the empty tables and answer my questions, then i’ll be really grateful.

Did he index the folder.name or child.Name for a key to name the data or did he use it for something else?

Why did he use the name of the folder?

Did he insert things like the folder.name in a table(dictionary) ?

  • Yes, he is creating a new index from the table; he’s using the name of the folder for the data table and child for subdata. Example: data["foo"] = 10. If I print the data, you will see “foo” inside, meaning you can index/call this foo simply print(data.foo) -- Output - 10.

Does it matter if he used a string like “ham” instead of the folder.name ?

  • It doesn’t matter what type of name you use as long as you know and what to index when using the table/dictionary.

How did he set the child.value by just child.name ?

  • What he’s trying to do there is check if subdata[child.Name] has a value; if it’s null, then use the value from child.Value meaning don’t change the value. To understand what this red line really means, you can just do this instead:
-- Ternary
child.Value = if subdata[child.Name] ~= nil then subdata[child.Name] else child.Value

Tysm! This really helped me understand the empty tables!

1 Like

I have one last question if you don’t mind answering.
image
Does the Value for the second parameter in the pcall contains the data and if it does, do you set it as the value for the data and subdata table. So for example in the data table/dictionary would be like, local data {folder.Name = value}. Also how does the script know which folder has the correct value to set?

No, the second argument of a protected function is the argument for the function that you are protecting. Example:

local function foo(bar: string)
    print(bar) -- Output: "bar"
end

-- instead of doing this
pcall(function()
   foo("bar")
end)

-- simply pass the argument inside the pcall
pcall(foo, "bar")

It checks if the name of the folder is indexed inside the table.

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