1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Help with SharedVars and Tables

Discussion in 'Development' started by TacticalToaster, Jun 18, 2018.

  1. TacticalToaster

    TacticalToaster Clockwork Customer Active Member

    So, I've been creating a plugin that creates an equipable gear system similar to Clockwork's clothes, but with more slots to equip to. Currently, everything seems to be working fine, the only issue I'm running across is networking to the client. I've scoured Clockwork and the forums, but came up with nothing that works. What I want to do is network a table between the server and client, so whenever I change something in the gear table (that contains several slots that are tables, each with itemID and uniqueID values) the client also changes its own gear table. Here's the code that I have related to the networking:
    -- A function to network the player's gear data.
    function playerMeta:NetworkGearData()
        local gearData = self:GetGearData(); //This'll be a table
        self:SetSharedVar("Gear", gearData); //Tried using the shared table method, doesn't work. The Network Proxy doesn't seem to notice any changes
    function GEARSLOTS:LocalPlayerCreated()
        Clockwork.kernel:RegisterNetworkProxy(Clockwork.Client, "Gear", function(entity, name, oldValue, newValue)
            if (oldValue != newValue) then
                if (newValue != {}) then
                    Clockwork.GearData = newValue;
                    Clockwork.GearData.headSlot = {itemID = nil, uniqueID = nil};
                    Clockwork.GearData.chestOneSlot = {itemID = nil, uniqueID = nil};
                    Clockwork.GearData.chestTwoSlot = {itemID = nil, uniqueID = nil};
                    Clockwork.GearData.legSlot = {itemID = nil, uniqueID = nil};
                    Clockwork.GearData.bagOneSlot = {itemID = nil, uniqueID = nil};
                    Clockwork.GearData.bagTwoSlot = {itemID = nil, uniqueID = nil};
    To really get an idea of how I got this structured, just take a look at the clothes stuff in base clockwork. I really am stumped at this point.
  2. duck

    duck Phant0m Legend Crusader

    if (newValue != {}) then
    This will never be false.
  3. TacticalToaster

    TacticalToaster Clockwork Customer Active Member

    I'm assuming I'd have to use table.empty instead then? Can't test it currently, as I'm away from my computer, but I'll test it as soon as I return home
  4. TacticalToaster

    TacticalToaster Clockwork Customer Active Member

    So, I've done some testing. First test was just doing a fix to the if statement to check that the table is empty. I ended up getting an error saying that I hadn't registered the sharedVar. I tried the ClockworkAddSharedVars hook from here but I still got the same error. I tried doing the shared tables solution you posted but the RegisterNetworkProxy isn't even running (added a print at the beginning of the callback, it doesn't run). It appears that my problem right now is properly networking the table. I'd like to keep this as close to how the clothing works, but if I have to make a work around if its impossible doing it this way then I will

Previous Readers (Total: 0)