Hiwi!! Thank you for reading, can someone tell me a good way to access this?
(All code its just an Example typed directly in the post)
I have a table like this:
local list = {
{name = "Violet", took = false},
{name = "Crimson", took = false},
{name = "Gray", took = false},
}
I can use:
for _, i in pairs(list) do
if i.name == "Crimson" then
-- do something
end
end
how to usetable.find(list, "Crimson")?
Related question. Why this Players Table works fine with table.find() and the Color List wont work with table.find() if Im doing the exact same process?
local playersList = {
{play1 = Dev_Peashie, play2 = AnotherName, team = "Crimson"},
{play1 = BlaBla, play2 = BlaBla2, team = "Violet"}
}
That list is created by events, storing the Player instance, and can be accessed without a loop. Just table.find(playersList, playa) by providing another player instance inside the playa var from an event in order to find the index inside the table. But its not working when Im trying to find a string inside the Color Table.
I realized I sounded confusing so what I mean is the table has defines as you write so you have 3 in the list and in 1 is somthing so you have to see if name = “crimson
Still a little confusing sorry
I really dont get what you mean. The table defines itself as its been written, so I have 3 nodes in the list? and in 1 is something? Values. But you support that I should do the loop and forget about the table.find()? xD Thats what u mean?
Dont worry, Im confusing too, and thank you for the help. But. I kinda need the table.find in order to find the index for that node and delete or make stuff with it… Mmmh Im gonna think why its not working with strings and works with players
Looks like the hierarchy of the table does not allow table.find() to work with it. Even when it’s in the next scope, where it is a dictionary instead. Use a regular for loop to check all the keys. You cannot use table.find() because it’s limited to arrays.
But, the Players List is exactly the same hierarchy as the Color List, the only difference, is that the colors list is made by Strings, and the Players List contains Player Instances. Why table.find() works with the Player List and not the Color one?
If I cannot use table.find() to find a string inside “name”, whats the best way to get the node index in order to delete it?
During the loop, make an increment var? and use that var to select a node in the list? seems like a mess… Any way to get the index of that node in color list without failing?
Actually, now when you mention it, you’re not explaining exactly what the table was supposed to do. Can you elaborate the reason why the list look like this?
By that question you mean, that maybe I should change the whole approach, cause Im doing a mess with tables? xDD well thats a great answer, cause probably your answer its perfectly right!! I made a mess xD
Kinda fusing systems… Old systems I made for a game and after weeks of building, I got some new tables and I want to “sync” them…
The purpose of the tables is irrelevant for my question. Cause I cant find why table.find is not working with strings and works with player instances.
Im still learning, and Im sure theres a better approach, but, it will take me lots of time to change that. Now I just need to find the index node in a list that looks like the Color List I showed
It’s 100% possible I missed what you’re trying to do (I think it’s safe to say at this point everyone is confused.)
From what I can tell, you’re trying to identify the index of the value you’re iterating if it matches a condition, in this case the condition being teamed Crimson.
local list = {
{name = "Violet", took = false},
{name = "Crimson", took = false},
{name = "Gray", took = false},
}
for Iteration, Value in pairs(list) do
if Value.name == "Violet" then
print(Iteration) -- output: 1
end
end
If I missed your point let me know and I’ll just delete this lol
Yup, I did that, maybe the example I gave is a little brief. But yes, doing that loop, and use the index. But Im confused about the order of the list, maybe a player joined while that the loop is happening, made a team, or left the game and changing the list, so using the Iterarion value, to handle the index node, I think it will get mixed with other values, and maybe deleting a different one that is not the one I was searching… Idk… I know nothing about “issues” happening behind curtains.
So I wanted to make sure its the right index, by searching directly into the table and get the index by local index = table.find()
Yup Im using the loop, but, Im a little scared that the values are not correct while scanning the list. So double checking with table.find()
Each team is made of 2 players only, So Im just tagging “play1” and “play2”. Because the table exist in the module. I access that table and do things with each player, “play1” has some powers, play2 has different ones, and working on team, sometimes I need to act on one of them specifically, with the table containing those tags, I found it easy for me to handle with that 2 players team
Makes totally sense, I never used dictonaries before, I just place everything as a value inside a table. Mainly because while researching, I found bad comments about dicctionaries and that common tables are more flexible. Maybe thats wrong, and I should change to that. Let me think xD cause I have to change a lot in many scripts in order to make it work like that u ,u