net question

I want to get variable in client from server.

Problem is function goes on even if I received a variable and its return nil.
I want wait until net receive got a variable.




-- serverside

net.Receive("blah", function(len,pl)

    local ent = net.ReadEntity()


    net.Start("blah2")

    net.WriteString(ent:GetHisVar()) -- any serverside function

    net.Send(pl)

end)


-- clientside
function x(ent)


local var

net.Start("blah")

    net.WriteEntity(ent)

net.SendToServer

-- function is continuing...

net.Receive("blah2", function()

    var = net.ReadString()

end)




return var


end

-- returns nil


I know that I shouldn’t use net receive in a function.
What should I do, is there a shortcut for just getting variables between client and server?

There are Set/GetGlobal(Datatype) functions. They basically set a NWVar on the world entity if I recall correctly. You can use that.

Net library is asynchronous, meaning it will not wait to receive something before calling other code.