Fist Posted February 23, 2017 Share Posted February 23, 2017 Hello guys ! I want to know how i can remove specific data from such table as this -- table invitations = {} -- this is how i instert data into it later i just pass whole table and get specific information by unack(invitations) then i get "player" and "team" data table.insert(invitations,{player,team}) -- but i need somehow remove/delete that "team" data which is packed like code above, is there any way to do it? Link to comment
pro-mos Posted February 23, 2017 Share Posted February 23, 2017 function deletePlayerInvite(player) for i, k in pairs(invitations) do if k.player == player then k = nil return true end end end small code written on my phone 1 Link to comment
Administrators Lpsd Posted February 23, 2017 Administrators Share Posted February 23, 2017 (edited) Let me suggest an easier way to insert into the table in the first place. -- table invitations = {} local playerName = getPlayerName(player) -- get the player's name invitations[playerName] = { player, team } --store info about player and team, key = playerName Now later on in your code, you can remove entries from the table like so: table.remove(invitations, playerName) --table.remove(table, key) Better than looping through all entries imo. Edited February 23, 2017 by LopSided_ 1 Link to comment
Fist Posted February 23, 2017 Author Share Posted February 23, 2017 23 minutes ago, LopSided_ said: Let me suggest an easier way to insert into the table in the first place. -- table invitations = {} local playerName = getPlayerName(player) -- get the player's name invitations[playerName] = { player, team } --store info about player and team, key = playerName Now later on in your code, you can remove entries from the table like so: table.remove(invitations, playerName) --table.remove(table, key) Better than looping through all entries imo. But if i do that in that way, how i can pass table to client side? I'm doingi t like this -- passing to client triggerClientEvent(source,"updatePlayerInvites",source,invitations) -- then this is how i get it on client side guiGridListClear(inviteListGridlist) for _,v in ipairs(invitations) do local player,team = v; -- here im not sure how to receive those data if (player == localPlayer) then local row = guiGridListAddRow(inviteListGridlist) guiGridListSetItemText(inviteListGridlist, row, 1, team, false, false ) end end Link to comment
Fist Posted February 23, 2017 Author Share Posted February 23, 2017 1 hour ago, pro-mos said: function deletePlayerInvite(player) for i, k in pairs(invitations) do if k.player == player then k = nil return true end end end small code written on my phone also it didn't work Link to comment
pa3ck Posted February 23, 2017 Share Posted February 23, 2017 function deletePlayerInvite(player) for i, k in pairs(invitations) do if k[1] == player then -- k.player doesn't work because player is not the index k = nil return true end end end 1 Link to comment
Fist Posted February 24, 2017 Author Share Posted February 24, 2017 thank you guys, works perfectly. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now