1. Hiya,

    I have a plugin with methods that expect a position object. Sometimes there are events that don't have a position so I tried passing these as null.

    In the plugin these result in a NullExceptionError which came as a surprise to me :p

    Basically I want to pass a value that I can detect as empty or null at the other end, the positoin object derives from player.transform.position.

    If you need more info please shout - don't have code examples in front of me but can grab them later.

    Thanks in advance,


    Tony.
     
  2. Wulf

    Wulf Community Admin

    The other end would have to detect it, you can't pass a null if the target method cannot handle that.
     
  3. a Unity Vector3 is a non-nullable value type. You cant send it as null. Would sending Vector3.zero and checking == Vector3.zero on the other end work?
     
  4. Thanks for the replies - gives me some hope this is fixable :)

    The code I have so far is below - first the initiator:

    Code:
            void OnPlayerDisconnected(BasePlayer player, string reason) {            /* Player left the server */            string log = player + " left (" + reason + ").";
                string type = "info";
                EventLogger?.Call("AppendToLog", type, log, null);        }
    And then the plugin that is being called:

    Code:
            void AppendToLog(string type, string log, Vector3 location) {            Int32 nowTimestamp = GetTimestamp();
                log = Uri.EscapeDataString(log);            /* Append to event log */            if (location == null) {                eventLog.Add(new {
                        Timestamp = nowTimestamp,
                        Type = type,
                        Event = log,
                        LocationX = "",
                        LocationY = "",
                        LocationZ = ""
                    });            } else {                eventLog.Add(new {
                        Timestamp = nowTimestamp,
                        Type = type,
                        Event = log,
                        LocationX = location.x,
                        LocationY = location.y,
                        LocationZ = location.z
                    });            }        }
    Can be more specific about how I would implement, or detect the null?


    Thanks in advance.
     
  5. Seems to be working now - I tried what EinTime suggested.

    Thanks :)