- Joined
- Jul 16, 2015
- Messages
- 212
- Thread Author
- #1
Was in the Developer chat and @Aidden explained the difference between Null/Validity checking. Here is an adaption of the conversation:
When you get an object from the game, you store that item in memory (RAM), if the object didn't exist in game, the memory location will therefore have nothing in it, essentially being null. However, if the object did exist in game, data about the object is then stored in memory so the memory location that the object points to is being used and isn't going to change unless you tell the program to change it.
You need to first null check in order to make sure the object actually existed in the game. If you need to know if the object is still in the game after that, an isValid check would be suitable as it's live state isn't reflected in memory. What's stored in memory is simply a snapshot of how the game was at the time of setting the objects value and doesn't record live changes within the game unless you're constantly re-setting the variable.
Short and sweet.
When you get an object from the game, you store that item in memory (RAM), if the object didn't exist in game, the memory location will therefore have nothing in it, essentially being null. However, if the object did exist in game, data about the object is then stored in memory so the memory location that the object points to is being used and isn't going to change unless you tell the program to change it.
You need to first null check in order to make sure the object actually existed in the game. If you need to know if the object is still in the game after that, an isValid check would be suitable as it's live state isn't reflected in memory. What's stored in memory is simply a snapshot of how the game was at the time of setting the objects value and doesn't record live changes within the game unless you're constantly re-setting the variable.
Short and sweet.
Last edited by a moderator: