Hello there, dear members! I’m currently having some issues reading all values from a table. I tried using the pair and ipairs functions, but none of them worked. For some reasons, the script display anything in the console. Here is my table:
--NOTE: This script must print "Standard".
local function LoadRooms()
warn("Printing rooms...")
for _, v in pairs(Configuration.Rooms_Settings) do
wait()
warn(v)
end
warn("Ended.")
end
LoadRooms()
local Table_Manager_Test = require(game.ServerScriptService.Table_Manager_Test)
local Table = Table_Manager_Test.Rooms_Settings
local function LoadRooms()
warn("Printing rooms...")
for Key, Value in pairs(Table_Manager_Test.Rooms_Settings) do
wait()
print(Key)
end
warn("Ended.")
end
LoadRooms()
First of all I recommend checking out those links before reading!!!
Once you check out those links and try your best to understand, come back to this reply and continue reading a brief explanation.
In his case he has a ModuleScript placed inside ServerScriptService which contains a dictionary!!!
The reason he is using pairs() in a for loop is because his table in a Module Script is actually a dictionary.
There are 3 types of tables.
Array
Dictionary
Metatables [Powerful Tables]
He is looping through the dictionary with Key variable, Value variable and in the brackets of pairs() function he placed the location of that dictionary he is going to loop through.
In his case Key variable is _ which I don’t recommend using and Value variable is named v.
A dictionary contains a pair key-value variable, where key is the name of what you are defining and value is the actual value of that key.
In his case he made a mistake and wanted to print or warn the Value, but he actually wanted to print the Key. Key in the dictionary in the Module Script is Standard.