table question

I have a 3d2d button and I’m wondering if its possible to make that button remove the content from a table but when you press it again, the content from that table re appears?

Tried with table.empty but of course that only removes the table. Im guessing I’d have to copy the table somewhere and then paste it back after it gets removed?


    if isMouseOrUseDown and table.Count( blabla.ammo ) > 6 then
    table.Empty(blabla.ammo)
end

table1 is just the config table that holds some strings, this is for a vending machine.

You should make it clearer… What table are you talking to? Provide some code and describe what you’re getting vs what you’re expecting.

Can you show your code? (Just the table and button use function)

Im basically trying to do a page system in 3d2d where page 1 is the first 6 elements and page 2 are the next elements and so on


--tables as a page

local page1 = {} -- first table containing first page
	
local page2 = {} -- second table containing second page and so on
	
local curpage = page1 -- use this for current page, and set the page you want to start from
	
if isMouseOrUseDown  then -- simple func. switching between 2 pages
	if curpage == page1 then
		curpage = page2
	else 
		curpage = page1
	end
end

Simplest example for page system

For more than 2 pages you can use loop func.

Thing is, I’m using this method to add more elements to the table and using your idea with table for page 1 and 2 would have me re write everything.


function blabla:AddAmmoType( ammoType, data )
blabla.ammo = {}
    local consData  = {}
    consData.name   = data.name or "invalid ammo name"
    consData.desc   = data.desc or "invalid ammo description"
    consData.price  = data.price or "invalid ammo price"
    consData.amount = data.amount or "invalid ammo amount"
   blabla.ammo[ammoType] = consData
end