1. Hi.

    This is my code:
    Code:
    void Loaded()
            {
                var containers = UnityEngine.Object.FindObjectsOfType<StorageContainer>();
                timer.Repeat(12, 0, () =>
                {                    foreach (StorageContainer container in containers)
                        {
                            foreach (Item sc in container.inventory.itemList)
                            {
                                if (sc.amount > 55000)
                                {
                                    PrintToChat("TEST:");
                                }
                            }                    }
                });
            }
    Error:
    Code:
    Error] Failed to run a 12.00 timer in 'Testing v1.0.0' (NullReferenceException: Object reference not set to an instance of an object)
    The truth is, I don't have any idea what is wrong.

    Thanks!
     
  2. Wulf

    Wulf Community Admin

    One of the items you are trying to call doesn't exist, which means it is "null", so you'd need to do some debugging to find out which one is causing it. My guess is that you're either trying to get an inventory that doesn't exist, or something along those lines.
     
  3. Maybe, but if I remove that timer and I put a command like this:

    Code:
    [ChatCommand("lalala")]
            void estamostesteando()
            {
                var containers = UnityEngine.Object.FindObjectsOfType<StorageContainer>();
                foreach (BasePlayer player in BasePlayer.activePlayerList.ToList())
                {
                    foreach (StorageContainer container in containers)
                    {
                        foreach (Item sc in container.inventory.itemList.ToList())
                        {
                            if (sc.amount > 50)
                            {
                                // bla bla
                            }
                        }                }
                }
            }
    It works.
     
  4. Wulf

    Wulf Community Admin

    The timer can't really throw an NRE. The code you posted there is a bit different too. Also, why are you trying to do this in Init()? It would be better to handle it in OnServerInitialized().
     
  5. You will have to use FindObjectsOfType inside of the timer because the StorageContainers will be killed and spawned along the time. So your timer hits when one or more doesn't exist anymore.