Help with Tables

I’m looping through players in game and inserting a Frame:Clone for each player into a Table. Each Frame is given the same name as the player.
From elsewhere in the script, when again looping through players in the game, how do I check if the Table already has a frame named after the player already in the table?
Thanks

I’ve tried…

if not table.find(PlayerFramesTable, plyr.Name) then

if PlayerFramesTable[plyr.Name] == nil then

if not PlayerFramesTable[plyr.Name] then

…with no luck.

1 Like

I would recommend instead assigning new elements using:

FrameTable[player] = frame

You can then check if a player has a frame using:

if FrameTable[player] then

this works because Lua evaluates a nil object as false and anything non-false as true

(sorry for bad formatting, I’m on mobile)

1 Like

As an aside, here’s why the three things you tried didn’t work:

  1. You were searching through the table for a string matching the player name, NOT the frame instance.
  2. The [] operator only gets the value of a specific index, and since you presumable didnt set an index when populating the table, the indices are represented by numbers instead of strings. For example, item 1 would have an index of 1.
1 Like

Thanks, that’s working. How do I now remove the Frame from the table if/once the frame is found?

Using:

table.remove(FrameTable, player)
or
FrameTable[player] = nil
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.