Yeah Im literally so confused right now I dont know what to do at all
Aren’t you just rechecking if the value exists, even though you’ve looped through the table and have gotten that value?
I need to check if the the info in the mission which is the name i need is the index of the uncomplete mission table
I am deriving two conclusions as to what you are trying to do:
- Are you trying to check whether the mission’s key matches the name stored in the array?
for missionName, missionContents in pairs(UncompletedMissions) do
if missionName == missionContents[1] then
print("matches")
else
warn("doesn't match!")
end
end
- Are you trying to retrieve the mission’s contents as long as you know the name?
local function getUncompletedMissionContents(missionName)
local missionContents = UncompletedMissions[missionName]
if missionContents then
return missionContents
else
print("This mission is already complete!")
end
end
side note
I think you would benefit a lot from making the mission contents a dictionary:
local info = {
[name] = {
Name = name,
Type = typ,
Description = des,
Reward = reward,
Progress = prog,
Argument = arg[1] -- can't be inferred lol
}
}
Then you would make your code way more readable, e.g:
-- as opposed to missionContents[1]
if missionName == missionContents.Name then
print("matches")
end
And you can rename missionContents
to just mission
to make it fit in your mind more as an object than strictly a data structure.
other side note
I think a better solution to this (and your last problem) would be including a Status
field in each mission instead of putting them in a category, that way when you check for a mission, you know that it either exists or it doesn’t, and it can’t be found anywhere else.
It would be the equivalent of a structure like this:
local allMissions = {
[name] = {
Name = name,
Status = "Inactive",
Type = typ,
Description = des,
Reward = reward,
Progress = prog,
SomeOtherKey = arg[1],
},
-- include all other missions here with this format
-- (if you want)
}
What you ask for and what you show seem to be very different. I’ll assume you want what you ask for.
Also note that you have shown "Uncomplete Missions"
and "UnComplete Missions"
Maybe you’re looking for something like this?:
-- Note capital C in "UnComplete Missions" -- Is this what you want?:
local UnCompleteMissions = _G.PlayerData[plr.UserId]["Inventory"]["UnComplete Missions"]
local missionName = getMissionName() -- Assuming you have something similar
local incompleteMission = UnCompleteMissions[missionName]
if incompleteMission then
-- Do stuff w/ incompleteMission here
end