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
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.
Detecting a null object, or other solution?
Discussion in 'Rust Development' started by Rebajas, Jan 4, 2017.
-
Wulf Community Admin
The other end would have to detect it, you can't pass a null if the target method cannot handle that.
-
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?
-
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); }
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 }); } }
Thanks in advance. -
Seems to be working now - I tried what EinTime suggested.
Thanks