Very weird, table data not loading, PrintTable not calling, loops not running through a table that definitely exists.

I’ve got some very interesting problems that are delaying a project quite a bit. Here I have my character creation, with for some reason has the following problem:

So how it goes is it sends a list of characters serverside, using usermessage, and inserts them into a clientside table defined in cl_init, which will be pasted below. I put the usermessage.Hook above the function that contains all my derma, and yet PrintTable( TheTable ) can’t be called, it completely skips it, anything that has to do with the clientside table doesn’t get called. What I’m doing is looping through the clientside table, and trying to add a button for every index in the clientside table to a DPanelList using the AddItem function, any function being called in the for loop didn’t get called, including random prints.

Here is the cl_init.lua

– snipped.

Now before you say “You’re not sending any data.” while I have the menu open, and i use lua_run_cl PrintTable( cl_characters )
** all ** the data that should be there, is there.

Also when we use lua_run PrintTable( player.GetByID(1).Characters ) it also has all the data.
The main menu is being called right on initialspawn.

Sorry if the code looks messy, we’ve frantically been adding and changing things to try and fix it.

Sometimes I’ve had to add a timer to code that required data from a usermessage. I think the PrintTable and the loop below it are being called before the usermessage hook has had time to recieve the data from the server. Just a guess, but try it.

Well normally the menu is being opened on initialspawn, but we tried calling the menu manually, about 30 seconds after joining, it wasn’t the problem. tomarrow I’ll give it more tests, but I think it definitely has something to do with the way the data is being called.

I just want to make sure of something before you try a different tactic. You used a timer within the menu right?

Something like this:

timer.Simple( 1, function()
PrintTable( cl_characters )
Because you’re not sending the data until the very instance before you use PrintTable otherwise.

Usermessages are discarded on the client if the client isn’t ready to accept them. A better way to do it is have the client run a concommand on InitPostEntity (ie when they’re ready) so the data won’t be discarded.

But see, what doesn’t make sense is, right when I open my character loading menu, no characters show up, but if I type lua_run_cl PrintTable( cl_characters ).

it has data.

i fixed it, but I’m bound to have problems with live updating the data, so… we’ll see.

[editline]16th July 2011[/editline]

Okay, now I have another problem. It seems to be creating duplicate indexes on the clientside table.

With this code, the cl_characters table contains a list of all there characters. But everytime this usermessage.Hook is called, it adds another index to that table, with the same name. for example when I use printtable it’d come out like this

usermessage.Hook( “clcharupdate”, function( um )
–if ( !table.HasValue( cl_characters, um:ReadString()) ) then
table.insert( cl_characters, um:ReadString() )
–print(“Already had index!”)

So I figured the problem was obvious, I just needed to check if the cl_characters table had a value in it already.

So I did this.
usermessage.Hook( “clcharupdate”, function( um )
if ( !table.HasValue( cl_characters, um:ReadString()) ) then
table.insert( cl_characters, um:ReadString() )
print(“Already had index!”)

I did a check, and then there is -still- the index duplicating problem, except the problem now, the indexes don’t have text.

There is only 3 characters, the test button is just there, ignore it.

Normally, each of those little buttons have text on them, with the character name. Now, they have no text. And even though there are 3 characters, it still seems to duplicate the index, making six.

Indexes are only duplicating when the usermessage.Hook is getting called, but it still shouldn’t duplicate because i’m doing a check to see whether to insert the data or not into the cl_characters table.

Your problem is the way you call the string.
Do this.

[lua]usermessage.Hook( “clcharupdate”, function( um )
local charid = um:ReadString()
if ( !table.HasValue( cl_characters, charid) ) then
table.insert( cl_characters, charid )
print(“Already had index!”)

Worked, I thought about that but didn’t try it.

Useful Tip.

Usermessages are called in the order you send them.
So your example would act as though two strings where being sent when you only wanted the one to be recieved.

I already know this.