How do I nest net.Recieve inside another net.Recieve?
8 replies, posted
I'm trying to do logic recieved in one net.recieve based on variables that would be defined by a second net.recieve. I've tried nesting them both ways but neither configuration seems to work.
Note that it doesn't error, it just doesn't work.
[CODE]
net.Receive( "SkillUI", function( )
--code
net.Receive("lastroundpoints", function(len)
local LRP = net.ReadInt( int, 32 )
local prevroundtext1 = "Last round you earned"
local prevroundtext2 = LRP.. " points"
draw.SimpleTextOutlined( prevroundtext1, "Trebuchet18", 485, 30, Color( 0, 0, 0, 255 ), 0, 0, 0, Black )
draw.SimpleTextOutlined( prevroundtext2, "Trebuchet18", 485, 45, Color( 0, 0, 0, 255 ), 0, 0, 0, Black )
end)
--other code
end
[/CODE]
This is all inside of a vGUI panel. Basically I'm trying to draw how many points you earned 1 round ago in a panel, but those points are defined in an entirely separate area of the gamemode, so I'm using net.Send to get the integers from the server to the client.
my net.Send code looks like this:
[CODE]
for k, ply in pairs( RLIST ) do
int = --lots of math here
ply:Points( int )
net.Start("lastroundpoints")
net.WriteInt(int, 32)
net.Send( ply )
end
[/CODE]
edit note: I also do have my util.AddNetworkString("lastroundpoints") placed correctly in my init.lua
other edit: those fonts do work, I've re-made them myself to be like they were in gmod 12. I'm calling the same font in other places of my code and it works perfectly, that's not the issue.
third edit: I fixed a syntax error and now it's erroring with this error:
[CODE]
[ERROR] addons/pyroranksys/lua/autorun/command.lua:135: bad argument #1 to 'ReadInt' (number expected, got nil)
1. ReadInt - [C]:-1
2. func - addons/pyroranksys/lua/autorun/command.lua:135
3. unknown - lua/includes/modules/net.lua:31
[/CODE]
line 135 is this line:
[CODE]
local LRP = net.ReadInt( int, 32 )
[/CODE]
I'm very confused because the variable int is very clearly defined in the net.Send. I even changed it to a flat number so I could be sure it was correctly defined.
the 2nd net receive isnt activated until the server sends the net message "lastroundpoints"
the first wont be activated unless it receives "SkillUI", and you cant have 1 activate the other. your net.start/send needs to be both
Is there any way I could use the "lastroundpoints" net message to define a variable for my UI to use? I also need that variable to be clientside only, which makes it even more complicated.
[QUOTE=CallMePyro;42560486]Is there any way I could use the "lastroundpoints" net message to define a variable for my UI to use? I also need that variable to be clientside only, which makes it even more complicated.[/QUOTE]
It should be "net.ReadInt(numOfBitsSent)", "net.ReadInt(32)" in your case.
Sorry I'm too much of a newb to grasp what you meant :(
so I should keep the net recieve's as they are, nested inside eachother, but change my lastroundpoints "net.ReadInt( int, 32 )" to be "net.ReadInt(32)" ?
edit: I did that and again it doesn't error, and doesn't say that my integer is undefined, but it doesn't draw the text in the UI. I'm so confused.
double edit: Actually the integer is defined, and will print correctly through print(LRP) within the UI but I still can't figure out how to draw it.
triple edit: OMG it works now thank you so much! I swear to god as soon as I get my paypal account up again I'm showering you in gold.
I would appreciate it if you could explain WHY, because I have absolutely NO IDEA why it worked.
This doesn't make any sense anyway. Why don't you just send the net message when it's needed? You shouldn't have to put it inside another net receive in the first place.
[QUOTE=brandonj4;42561245]This doesn't make any sense anyway. Why don't you just send the net message when it's needed? You shouldn't have to put it inside another net receive in the first place.[/QUOTE]
Because the number that I'm sending doesn't exist until the end of the round when it's calculated, and it's really only used for the display UI. I guess I could call it with a function but wouldn't that have the exact same result?
[QUOTE=CallMePyro;42561268]Because the number that I'm sending doesn't exist until the end of the round when it's calculated, and it's really only used for the display UI. I guess I could call it with a function but wouldn't that have the exact same result?[/QUOTE]
I think you're forgetting that to draw on the screen, it needs to be in a hook that draws, on the screen.
No it's drawing 100% correctly now, very much because of your help. I'm using the Paint function to draw my text, and just supplying a concatenated text variable with the net.send is all. I just need that variable to get clientside and everything's peachy :)
Sorry, you need to Log In to post a reply to this thread.