what do I do now?

Okay. So i’m trying to send a umsg so that the information in my data is listed in my DListView. So here is my first umsg:
[lua]
function loadtrail(ply,cmd,args)
local read = file.Read(“player_trails/”…string.Replace(ply:SteamID(),":","_")…".txt")
umsg.Start( “loadtrail”, ply )
for k,v in pairs( read ) do
umsg.String( v )
end
umsg.End( )
end

concommand.Add(“loadtrail”, loadtrail)[/lua]
and in my DListView:
[lua]
local DermaListView = vgui.Create(“DListView”, self)
DermaListView:SetPos(15, 160)
DermaListView:SetSize(80, 200)
DermaListView:SetMultiSelect(false)
DermaListView:AddColumn(“Trails”) // Add column
RunConsoleCommand(“loadtrail”)
DermaListView:AddLine(v) // Add lines
[/lua]
Here was my first error.


OnslaughtEvolved_v1.8\gamemode\commands.lua:448: bad argument #1 to 'pairs' (table expected, got nil)


So I decided to use table.Tostring like this [lua]
function loadtrail(ply,cmd,args)
file.Read(“player_trails/”…string.Replace(ply:SteamID(),":","_")…".txt")
local read = table.ToString(ply.Trails,“trails” , true)
umsg.Start( “loadtrail”, ply )
for k,v in pairs( read ) do
umsg.String( v )
end
umsg.End( )
end

concommand.Add(“loadtrail”, loadtrail)
[/lua]
But I got the same table error as before. So how do I fix it without having to redo my whole saving system? Any help is greatly appreciated.

In your first attempt you’re reading the file, but what it returns is a string, you can’t use pairs on a string, you need to use some function to parse it into a table.
If you stored the data using glon then you can replace pairs(read) with pairs(glon.decode(read)).

Think about it this way, if you’re given a string, how does it know how to get the next value?
There are ways of iterating with strings, but they require you to use some function like string.gmatch.

Depending on how you’ve stored the data you’ll need these functions.
**[Glon.encode

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Glon.encode)** **[Glon.decode

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Glon.decode)** These don’t necessarily give human readable output but you can always get the same values out of it again.
**[Util.KeyValuesToTable

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Util.KeyValuesToTable)** **[Util.TableToKeyValues

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Util.TableToKeyValues)** These output human readable, but it replaces all numbers with strings, which you probably don’t want to do.

**[String.gmatch

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=String.gmatch)** This is if you’re using some other bizzare method of encoding the data.

ah thanks. My data is stored in a table format so i’ll probably have to use Util.TableToKeyValues. Thanks for your help.

-Edit- now getting this error



Warning: Unhandled usermessage 'loadtrail'


so there must be something wrong with my usermessage.
[lua]function loadtrail(ply,cmd,args)
file.Read(“player_trails/”…string.Replace(ply:SteamID(),":","_")…".txt")
umsg.Start( “loadtrail”, ply )
for k,v in pairs( ply.Trails ) do
umsg.String( v )
end
umsg.End( )
end

concommand.Add(“loadtrail”, loadtrail) [/lua]
any ideas? Thanks

are you… hooking it on the client?

It doesn’t look like you’ve properly thought out your usermessages.
On the server when you’re sending it you need to send the size of the table as well. This is so it knows how many values to read.
This assumes your Trails table is in an array
[lua]-- this is just a fragment
umsg.Start(“loadtrail”, ply)
umsg.Short(#ply.Trails)
for i, v in ipairs(ply.Trails) do
umsg.String(v)
end
umsg.End()[/lua]
To read it again you do it like this:
[lua]usermessage.Hook(“loadtrail”, function(um)
local trails = {}
for i=1, um:ReadShort() do
trails* = um:ReadString()
end
LocalPlayer().Trails = trails
end)[/lua]
This is just how you send a table of Strings, it isn’t saying how you’re going to add these trails to your DListView. For that you’ll need some way of identifying which DListView to add them to.
You’d need to put something like MyDListView = self in the DListView’s Initialize function and in the usermessage.Hook function do MyDListView:AddLine(…).