Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Check if there is a key in a table with a specific value?

Asked by 5 years ago
Edited 5 years ago

Skip to the edit as the information below is incorrect.

I need to check if a player's ID is in a dictionary table. The problem is that the ModuleScript I'm using to get the table will return it like this:

local table = {
    ['name'] = "123456789"
}

Because of this, I can't really use something like if table[player.UserId] then, where a key would be like ['123456789'] = true. Is there a different way I could do this that would be compatible with this? I do not need the key to have a specific name. Thank you!

BIG EDIT: Apparently, the ModuleScript actually returns an array like this:

[{name="cardName",desc="cardDescription",...},{name="cardName",desc="cardDescription",...}]

This completely changes my question, sorry for the confusion.

0
what are the names of the keys in the table? royaltoe 5144 — 5y
0
the names of the key would always be 'name', but I just used 'id' as an example because the key name doesn't matter. now that I think about it, it might actually since the key name is always the same thing. hpenney2 53 — 5y
0
editing now to have the key name as "name".. hpenney2 53 — 5y
0
i'm still confused because you can't have multiple keys with the same name. what is name? the player's name? royaltoe 5144 — 5y
View all comments (6 more)
0
the API is going to return a new table every time, so the keys won't be in the same table. the key's name is always "name", the value is going to be the player's id. I can't change how the API works, so I'm stuck with this. hpenney2 53 — 5y
0
for reference, the API will give the JSON under the "Response" section at the link https://getenveloped.com/trelloapi/detail.php?resource=GetCardsInList but it will be decoded to a table with JSONDecode. hpenney2 53 — 5y
0
im helping someone else ill help u in a bit royaltoe 5144 — 5y
0
okay, also apparently it actually returns an array like [{name="cardName",desc="cardDescription",...},{name="cardName",desc="cardDescription",...}] which changes my question quite a bit hpenney2 53 — 5y
0
so what's the question now? royaltoe 5144 — 5y
0
almost the same thing, I want to search if a key in the array with the name "name" matches the user's ID. hpenney2 53 — 5y

Answer this question