net.ReadString multiple occasions, causing head to explode

I’ve got net.WriteString on multiple occasions here. 4 of them so far, and I just can’t seem get net.ReadString to read them all (I’m obviously trying to use net.ReadString 4 times). My head is about to explode over here, as I just can’t find anything related to this issue of mine.

As i understand, then you’re trying to send four times net.WriteString() with four different strings. There is a method that i would prefer to use.

Make a table:



Table = {}
Table[1] = "First string"
Table[2] = "Second string"
Table[3] = "Third string"
Table[4] = "Fourth string"


Then use net.WriteTable(Table) and net.ReadTable().
In the receive function you can define the different strings out from the table. I hope this can help you resolve your issue.

Post your code.

This is basically what I have right now:



net.Start("sendclass1")
      net.WriteString(house1 .. " | " .. house2 .. " - " .. class)
net.Broadcast()

net.Start("sendclass2")
      net.WriteString(house21 .. " | " .. house22 .. " - " .. class)
net.Broadcast()

net.Receive("sendclass1",function() 
	class1 = net.ReadString()
end)

net.Receive("sendclass2",function() 
	class2 = net.ReadString()
end)

In my experience, sending two net messages too quickly would cause the first one to be sent twice, and the second to never arrive. YMMV

Anyways, is that your full code? You don’t seem to be doing anything with the variables you create. Otherwise, it looks OK.

No it’s not my full code, it’s just parts of it, to show what is it I’m doing and what is it I’m trying to achieve

The code that you posted should work, provided that you’re calling net.Broadcast from the server and net.Receive on the client. I can’t say much else without seeing more code.

All I can say is that it isn’t working. class2 just returns nil

You could possibly check to see how many times “sendclass1” is received. If “sendclass1” is received twice, you can try to make a workaround by slightly delaying “sendclass2”.

They’re not guaranteed to be received in the correct order. Your best bet is to send both classes in one netmessage via two net.WriteString calls.

I’ve tried that aswell, and the result is the same. In theory, if you write two net.WriteString’s;
let’s call them net.WriteString 1, and net.WriteString 2.

then if I do net.ReceiveString twice, shouldn’t the first ReceiveString take the string from net.WriteString 1, and the second ReceiveString should take the string from net.WriteString 2?

I’m still in need of help with this, so throwing a little bump…

So what’s the issue exactly? From what I gather class1 and class2 are both nil clientside when they shouldn’t be?

Because the code you posted above was so minimal I have to ask, when are you sending the net messages? Also have you added the names to the string table with

util.AddNetworkString?

If you could post more code it’d be easier to pin point the issue.


net.Start("sendclass1")
      net.WriteString(house1 .. " | " .. house2 .. " - " .. class)

net.Start("sendclass2")
      net.WriteString(house21 .. " | " .. house22 .. " - " .. class)
net.Broadcast()

net.Receive("sendclass1",function() 
	class1 = net.ReadString()
end)

net.Receive("sendclass2",function() 
	class2 = net.ReadString()
end)

How about you post the actual code, you’re obviously doing something wrong.