Jump to content

help with tables


Fist

Recommended Posts

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
  • Administrators

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 by LopSided_
  • Like 1
Link to comment
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...