Jump to content

Duplicate lua network variable


Recommended Posts

Well now I've run into another fundamental issue I don't understand; replicas

I believe I've gleaned from context from other threads I've been reading trying to solve this issue that replicas are essentially the client-side component of any object that needs to be referenced by said clients, but I don't understand what drives this or even if it's 100% correct.

So recently I created a system by which Guano is renamed to a playfully ambiguous title in keeping with the game's sort of vague reference to natural bodily functions. I do this in my modmain.lua with the following code;

AddPrefabPostInit("guano",function(inst)
    inst:AddComponent("named")
end)

and everything is well and good until I try to perform this in a world with caves. I'm assuming it's because I added the named component artificially with no supporting logic of when to replicate it? (I notice there's a named_replica.lua in the components folder) but I have no idea how to go about fixing this. The specific error log being

Quote

[00:02:38]: replica named already exists!     scripts/entityreplica.lua:77 in (method) ReplicateEntity (Lua) <74-84>    
[00:02:38]: Registering duplicate lua network variable 2265808981 in entity guano[100062]
[00:02:38]: Break at: ..\source\simlib\Entity.cpp(347) :

 

Link to comment
Share on other sites

Clients should not have components, unless it is a replica of another component. Replicas are used when the client is supposed to read/write something from/to the server. If you have no need for something like that, then you have to remember that when adding components to an instance of a prefab, you should only do it when the code is being run on the server. To do this, you enclose the code in a server check.

if GLOBAL.TheNet and GLOBAL.TheNet:GetIsServer() then
	AddPrefabPostInit("guano", function(inst)
		inst:AddComponent("named")
	end)
end

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...