Issue creating and using Arrays / Table

Good day,

I am trying to display questdata for any Active Quests but the print statment below says it cant find Description. I am new to Arrays / Tabels and don’t know what is wrong with my print statment or maybe the way I am doing my Array is wrong?

the print statment is after my Array definition in my code.

print(tostring(QuestData[ActiveQuests.name].Description))


local ActiveQuests = {}
table.insert(ActiveQuests, { name = "Q1", status = 0 })

local questData  = {
	["Q1"] = {
			["ID"] = "1",
			["Name"] = "Q1",
			["Level"] = 0, 
			["NeededProgress"] = 10,
			["RewardType"] = "Gold",
			["RewardAmount"] = 100, 
			["Description"] = "Collect 3 Apples",
			["Chat1"] = "Can you do my quest",
			["Chat2"] = "Find three Apples",
			["Chat3"] = "I will reward you with 20 gold"
		},

put the print below the tables all the way at the bottom it should work fine

1 Like

you might have to change a few things for the indexes tho

2 Likes

Hi,

Yes it is at the bottom and still errors as below

Players.CanterCrow.PlayerGui.Quests.QuestScript:37: attempt to index nil with ‘Description’

Is QuestData[ActiveQuests.name] nil? Try printing it

Yes its nil, so I am not getting the name from ActiveQuests with ActiveQuests.name is my formating incorrect?

thanks

Try with

local index = 1
print(tostring(QuestData[ActiveQuests[index].name].Description))

EDIT:
Active Quests is a table:

local table = {
   [1] = {...}
   [2] = {...}
   ...
}
1 Like

@CanterCrow if the problem is now solved remember to close the post by marking the solution, have a nice day! :slight_smile:

Thank you I have managed to fix the issue I just had to understand tables and arrays better.