local dictionary = {
["Apple"] = {
color = "red"
numbers = 5
}
["Orange"] = {
color = "red"
numbers = 5
}
}
If you have the orange dictionary, so if you do print(orange) it prints color and numbers, but how would you get the name if you have orange, for example , print(orange.Name) should print orange, but thats not the way to do it, so how do you print the name of it?
If I have the dictionary orange as a variable
so if i do print(orange), it prints the color and numbers. How would I get that the dictionary name is “Orange”, since dictionary.Name does not exist, is there another way
Loop through the main Dictionary then, printing the keys & values
local dictionary = {
["Apple"] = {
color = "red"
numbers = 5
}
["Orange"] = {
color = "red"
numbers = 5
}
}
for Index, Value in pairs(dictionary) do
print("Name of fruit: ", Index)
print("Values of fruit: ", Value)
end
This is my main dictionary, right now I am connecting to an onserverevent that returns the RoadRace dictionary inside the RaceData dictionary, I want to get the race name (which is “RoadRace”), how do I do that?
When I used your method, it printed index as 1 and value as NumberOfRacers
I believe this is because your [“RoadRace”] is encased in square brackets, if you remove those it should be referenced as a custom Index
Try this:
RaceData = {
RoadRace = {
PlayersEnrolledInRace = {}
RaceMax = 0
NumberOfRacers = 0,
}
}
for Index, Value in pairs(RaceData) do
print("Name of fruit: ", Index)
print("Values of fruit: ", Value)
end