Jump to content

Problem with table.insert


Miika

Recommended Posts

Hello again.

I have problem with table.insert.

I have vehicle shop that saves data to tables and tables to element data.

Always when you buy new vehicle, it should add sub-table to main-table and fill sub-table with data that i want to save.

I also have panel where you can control your vehicles. Instead of showing data, the gridlist shows only number 1 in first column.

Part of my code:

[Server]

local data = getElementData(client, "wangcars.data")
			if not data then
				setElementData(client, "wangcars.data", {})
			end
			local data = getElementData(client, "wangcars.data")
			local ids = #data + 1
			local x, y, z = getElementPosition(wangvehicle[client])
			local rx, ry, rz = getElementRotation(wangvehicle[client])
			local t = {}
			table.insert(t, getVehicleName(wangvehicle[client]))
			table.insert(t, tonumber(id))
			table.insert(t, tonumber(ids))
			table.insert(t, tonumber(price))
			table.insert(t, c1 .. ", " .. c2 .. ", " .. c3 .. ", " .. c4 .. ", " .. c5 .. ", " .. c6)
			table.insert(t, x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz)
			table.insert(t, "indrive")
			
			table.insert(data, t)
			setElementData(client, "wangcars.data", data)

[Client]

function refreshlist()
	guiGridListClear(vlist)
	guiGridListAddColumn(vlist, "Vehicle name", 0.3)
	guiGridListAddColumn(vlist, "Sell price", 0.3)
	guiGridListAddColumn(vlist, "ID", 0.3)
	
	local table = getElementData(localPlayer, "wangcars.data")
	if not table then
		setElementData(localPlayer, "wangcars.data", {})
	end
	for i=1, #table do
		local row = guiGridListAddRow(vlist)
		guiGridListSetItemText(vlist, row, 1, table[i][1], false, false)
		guiGridListSetItemText(vlist, row, 1, table[i][4], false, false)
		guiGridListSetItemText(vlist, row, 1, table[i][3], false, false)
	end
end

The values  are tested and they're working fine. No errors in debugscript.

Edited by Miika822
Link to comment
39 minutes ago, Snow-Man said:

try this


table.insert(t, {id, ids, price, ...})

 

Thanks, i'll try this next time when i go to computer.

39 minutes ago, MR.GRAND said:

p_3623ct5r1.png

I think this table is general table for all players,
So you need to make special table for everyone .

This is local table and this is just part of the function. The function is called from clientside gui.

Link to comment
9 minutes ago, MR.GRAND said:

Ok try the code which wrote by @Snow-Man

and good luck 
^_^ .

I will :)

And btw I just noticed something that can be issue too. I forgot to change different column numbers so it's just replacing same text every time :D

guiGridListSetItemText(vlist, row, 1, table[i][1], false, false)
		guiGridListSetItemText(vlist, row, 1, table[i][4], false, false)
		guiGridListSetItemText(vlist, row, 1, table[i][3], false, false)

They're all 1 instead of 2 and 3

Edited by Miika822
  • Like 1
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...