1. Hi Guys,

    Could anyone please tell me what is that self referencing loop thingy about?

    I get a console error message when trying to save data with this function:
    Code:
    Interface.Oxide.DataFileSystem.WriteObject(dataFile, storedData);
    Error I am getting is:
    Code:
    > reload Auctioner
    [Oxide] 9:34 PM [Error] Failed to call hook 'Unloaded' on plugin 'Auctioner v0.0.2' (JsonSerializationException: Self referencing loop detected for property 'normalized' with type 'UnityEngine.Vector3'. Path 'auctionCurrent.seller.eyes.duckOffset.normalized'.)
    [Oxide] 9:34 PM [Debug]   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract contract, Newtonsoft.Json.Serialization.JsonContainerContract containerContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0
      at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonContainerContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonProperty property, Newtonsoft.Json.Serialization.JsonContract& memberContract, System.Object& memberValue) [0x00000] in <filename unknown>:0
      at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject (Newtonsoft.Json.JsonWriter writer, System.Object value, Newtonsoft.Json.Serialization.JsonObjectContract contract, Newtonsoft.Json.Serialization.JsonProperty member, Newtonsoft.Json.Serialization.JsonContainerContract collectionContract, Newtonsoft.Json.Serialization.JsonProperty containerProperty) [0x00000] in <filename unknown>:0
    This is data class I am trying to save:

    Code:
    class StoredData
            {            public Auction auctionCurrent = null;
                public List<Auction> auctionQueue = new List<Auction>();
                public List<Auction> auctionArchive = new List<Auction>();            public void NewAuction(BasePlayer seller, Item item, int price)
                {
                    Auction auc = new Auction(seller, item, price);
                    if (auctionCurrent == null) auctionCurrent = auc;
                    else auctionQueue.Add(auc);
                }            public void NextAuction()
                {
                    Auction auc = GetNextAuction();
                    if (auc != null)
                    {
                        auctionCurrent = auc;
                        auc.Start();
                    }
                }
                public void EndAuction()
                {
                    auctionCurrent.End();
                    auctionArchive.Add(auctionCurrent);
                    auctionCurrent = null;
                }
                public Auction GetNextAuction()
                {
                    if (auctionQueue.Count > 0)
                    {
                        Auction auc = auctionQueue[0];
                        auctionQueue.Remove(auc);
                        return auc;
                    }
                    return null;
                }            public StoredData() { }
            }
            class Auction
            {
                public string status;
                public BasePlayer seller;
                public BasePlayer buyer = null;
                public int startPrice;
                public int currentPrice = 0;
                public Item item;            public void Start() { status = "started"; }
                public void Queue() { status = "queued"; }
                public void Bid(BasePlayer buyer, int bid)
                {
                    if (bid > currentPrice)
                    {
                        this.buyer = buyer;
                        currentPrice = bid;
                    }
                    if (status != "bid") status = "bid";
                }
                public void End() { status = "ended"; }            public bool isLive() { return status == "started" || status == "bid"; }
                public bool isQueued() { return status == "queued"; }
                public bool isBet() { return buyer != null; }            public Auction() { }
                public Auction(BasePlayer seller, Item item, int price)
                {
                    this.seller = seller;
                    this.item = item;
                    startPrice = price;
                }
            }

    Is this because I use Item and/or BasePlayer class within my data class?
     
  2. Calytic

    Calytic Community Admin Community Mod

    Yes, specifically the BasePlayer in this case. Do not attempt to save the BasePlayer (use the userID). I would also discourage attempting to save the Item instance as well. Instead create proxy classes to represent the item as JSON.
     
  3. Well I don't really have to save any of these classes, I applied a workaround but it would make things sooooo much easier if I could save Item. Well, still learning, will get around this too.

    Thanks a lot!