-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared NetworkVarNotify callbacks #324
Comments
any update on this? |
C'mon 2 years have passed |
@kojidev You're wrong. 1 year 10 months and 18 days have passed. |
Github displays it as "Almost 2 years." No need to be pretentious over it. |
These should work with nw2 vars. |
http://wiki.garrysmod.com/page/Entity/SetNWVarProxy This is for NWvars2 and should work already. |
https://wiki.garrysmod.com/page/Entity/NetworkVarNotify should be updated then. Just seeing this as a regular forum user is all. |
Christ, still not fixed? |
Use NW2Vars |
hello please fix |
Thanks for the ping, @meepen. Is this an easy fix? It probabaly should be done. I forgot about the issues it caused me but im sure it will come around and bug me in the future. I do networking a lot. |
Can we pretty please get this fixed? |
Yeah I have the code for this ready but there's a big problem with this, and that is the callback is called too soon before the entity gets its Lua loaded on client, which you can understand is a problem. |
i'm sorry to keep bumping this, but is there any chance you resolved that issue? |
Nah, I keep finding issues with this, I have fixed a different issue for SWEPs already, but there's still similar problem where the callbacks would be randomly called for SENTs with wrong old value for no reason and the issue with callbacks being called to soon is really tricky to solve due to how networking is done in Source. I am semi tempted to just push what I have, but I probably should fix these 2 problems it has. |
Completely understand, and it's just been a huge issue not having this by default, because NW2 still have issues when messing with dormancy that I haven't had time to replicate for a report yet and there's no other good options for callbacks. It makes doing stuff properly (on-update) extremely hard. Hope you can get them solved soon. |
I know it's looked down upon to bump issues, but this is VERY important for me. I hate doing stuff in Think to check if stuff has changed. |
Find reliable ways to reproduce the NW2 issues would be a good way to get them fixed faster |
I'm not talking about NW2 things in this request |
I suggested it since NW2 has this functionality working already but needs fixing. |
I will put what I have onto Dev branch so you can test if there are any major issues with it, it should just work except for 2 things:
|
Dirty but nessesary |
Is it only float callbacks? If so it shouldn't be too big of a deal. The second one is completely fine and I can just do that in Lua if necessary |
It my tests it seems to be only floats that do the first thing. It's somewhere in the networking and I couldn't figure out what it is yet. |
I'll test this either tomorrow or tonight to provide useful feedback. Thank you so much. |
does the server have to be on dev? im running client dev and server main and i just get AddCSLuaFile()
ENT.Type = "point"
ENT.Base = "base_entity"
ENT.PrintName = "TTT Networking State"
ENT.Author = "Meepen"
ENT.Contact = "meepdarknessmeep@gmail.com"
function ENT:NetworkVarNotifyCallback(name, old, new)
printf("%s::%s: %s -> %s", self:GetClass(), name, old, new)
if (old == new) then
return
end
hook.Run("On" .. name .. "Change", old, new)
end
function ENT:SetupDataTables()
local types, vars = {}, hook.Run("InitializeNetworking") -- can just make this return {} and it should be fine
self:NetworkVar("Int", 0, "Test")
self:NetworkVarNotify("Test", self.NetworkVarNotifyCallback)
for _, var in ipairs(vars) do
-- blocked by issue https://github.com/Facepunch/garrysmod-requests/issues/324
if (not types[var.Type]) then
types[var.Type] = 1
end
printf("Registering variable %s (type %s)", var.Name, var.Type)
self:NetworkVar(var.Type, types[var.Type], var.Name)
self:NetworkVarNotify(var.Name, self.NetworkVarNotifyCallback)
if (SERVER and var.Default) then
self["Set" .. var.Name](self, var.Default)
end
types[var.Type] = types[var.Type] + 1
end
end
function ENT:Initialize()
self:SetPredictable(false)
end
function ENT:UpdateTransmitState()
return TRANSMIT_ALWAYS
end
hook.Add("TTTAddPermanentEntities", "ttt_state", function(list)
table.insert(list, "ttt_state")
end) e = e or ents.Create "thatent"
e:SetTest(2) |
Yes, the callbacks are all defined in Lua so the c++ side has to call to a new Lua function. |
Looks to all be working perfectly, I don't have any things that hit floats hard that aren't always able to be seen so I will have to test that eventually. I'm really loving this! |
Is this in the current version of gmod now? |
Yes |
Setting the DTVar right after creating the entity doesn't trigger the clientside callback. |
I found that invoking the callback in ENT:Initialize manually does the job |
Just to be clear and as a self note, this is still open because of the very first callbacks clientside (on entity spawn) are not being called due to a race condition in-engine. Facepunch/garrysmod-issues#4639 is also affected by this. There's also a nasty network related issue related to entity baselines that needs figuring out, which causes the callbacks clientside get called with seemingly garbage data for less than a frame and then get reset back to correct value. |
Clientside callbacks added with NetworkVarNotify aren't called by the engine when the server changes the value, but as noted in includes/extensions/entity.lua it looks like they were meant to be:
The text was updated successfully, but these errors were encountered: