Jump to content

Read only Property?


Recommended Posts

11 hours ago, CarlZalph said:

I'm not seeing any checks for if it's the server or client for when components start being added, and reference to DLC0003.

Is this for the single player version of Don't Starve?

No it's not for single player don't starve, I'm trying to port over the hamlet chests, Those sound names though shouldn't be causing the crash.

 

11 hours ago, CarlZalph said:

I'm not seeing any checks for if it's the server or client for when components start being added

Strange. I'm not sure what can explain this.

Link to comment
Share on other sites

1 minute ago, Omaremad74 said:

No it's not for single player don't starve, I'm trying to port over the hamlet chests, Those sound names though shouldn't be causing the crash.

Strange. I'm not sure what can explain this.

Well in DST there are networked variables that are read only to the client, which require the server to send the proper values.

If the code is being ran on both the client and server, then the client might be trying to set a value to one where it shouldn't.

 

Personally I'd check out other similar mods on how they create their chests and replicate it.  I'm not too familiar with the underlying behaviours of them myself, so to that I wish you the best of luck.

Link to comment
Share on other sites

6 hours ago, CarlZalph said:

Well in DST there are networked variables that are read only to the client, which require the server to send the proper values.

If the code is being ran on both the client and server, then the client might be trying to set a value to one where it shouldn't.

 

Personally I'd check out other similar mods on how they create their chests and replicate it.  I'm not too familiar with the underlying behaviours of them myself, so to that I wish you the best of luck.

So, I was able to get the chest working!.... Mostly atleast, You can open it and it has the extra 3 slots and you won't crash when putting items in. However it's purpose is to share its inventory with all other chests of its kind Which isn't working
 

Quote

if style == "root_chest_child" then
            inst:AddComponent("roottrunkinventory")
            inst:ListenForEvent("onopen", function() if TheWorld.components.roottrunkinventory then TheWorld.components.roottrunkinventory:empty(inst) end end) --GetWorld(()
            inst:ListenForEvent("onclose", function() if TheWorld.components.roottrunkinventory then TheWorld.components.roottrunkinventory:fill(inst) end end)
        end

This is my code, in the prefab files
 

Quote

local RootTrunkInventory = Class(function(self, inst)
    self.inst = inst
    self.inst:DoTaskInTime(0,function() self:SpawnTrunk() end)
end)


function RootTrunkInventory:OnSave()
    local data = {}    
    local refs = {}
    if self.trunk then
        data.trunk = self.trunk.GUID
        table.insert(refs,data.trunk)
    end
    return data, refs
end

function RootTrunkInventory:OnLoad(data)
    if data.trunk then
        self.cancelspawn = true
    end
end

function RootTrunkInventory:LoadPostPass(ents, data)
    print("POST PASS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
    if data.trunk then
        self.trunk = ents[data.trunk].entity
    end
end

function RootTrunkInventory:LongUpdate(dt)

end

function RootTrunkInventory:OnUpdate( dt )

end

function RootTrunkInventory:empty( target )
    local t_cont = target.components.container
    local cont = self.trunk.components.container
    if t_cont and cont then        
        for i,slot in pairs(cont.slots) do
            local item = cont:RemoveItemBySlot(i)
            print(item.prefab)
            t_cont:GiveItem(item, i, nil, nil, true)
        end
    end    
end

function RootTrunkInventory:fill( source )
    local s_cont = source.components.container
    local cont = self.trunk.components.container
    if s_cont and cont then        
        for i,slot in pairs(s_cont.slots) do
            local item = s_cont:RemoveItemBySlot(i)
            print(item.prefab)
            cont:GiveItem(item, i, nil, nil, true)
        end
    end    
end

function RootTrunkInventory:SpawnTrunk()
    if not self.trunk then
        print("SPAWN TRUNK!!!!!!!!!!!!!!!!!!!!!!!!")
        self.trunk = SpawnPrefab("roottrunk")
    end
    self.trunk:RemoveFromScene()
end

return RootTrunkInventory

And this is my code from the component its referencing, As you can see there are some print statements and im getting "SPAWN TRUNK!!!!" in my console but nothing else, And I'm not sure how to fix this, Any help is appreciated!

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...