Currently the type checker fails if the entity is invalid, though it shouldn't because an invalid entity is still an entity. This caused #1350.
Another example of what this breaks is assigning values to arrays. Currently arrays use the type checker on the value being assigned, if it fails it isn't put into the array. This is bad because it can mess up the sequentiality of an array. It's also a bit inconsistent because the construct for arrays doesn't use the type checker.
So
T = array(noentity()) # The NULL entity is in the first index
and
T[1, entity] = noentity() # Fails because the NULL entity doesn't pass the type checker
don't have the same outcome.
Generally speaking, when one writes in E2
if(Ply) {
# Do stuff with Ply
}
the expectation is that Ply is valid. I don't think we can break backwards compatibility that far to change this, though perhaps a hack is possible for specifically inserting null entities (or arbitrary falsey types) into arrays? Perhaps a set of type validity functions that checks for minimal compatibility with the type (isentity, istable, etc) which would be used in cases like this but not for truthiness.
That would still work fine as that's controlled by the is operator, not the type checker. Changing this would only change a few things.
I don't know of any issues this would cause, it'd actually probably fix a few.
Edit: If you really wanted to just make this fix the array issue, it could be done by removing the type check when assigning to the array. I don't see any reason for it to be there. Though that doesn't change the fact the type checker shouldn't check for validity. Also doesn't fix the other issues by having it check validity.
foreach will loop over NULL entities in arrays instead of ignoring them.
I wouldn't want this behavior in my E2s though since it would add more ops for no gain
I wouldn't want this behavior in my E2s though since it would add more ops for no gain
That's a completely different issue.
I suggest to introduce iterator functions to use with foreach statement, so that would handle such case (and more).
This is the way it should be.
@Divran avoid putting nulls in your arrays then
@Nebual doesnt matter cos I use regular for loops almost all the time anyway lel
If I understand correctly, it was previously possible to end up with invalid entities in an E2 array (ie. Spawn prop, put in array, remove prop, nothing automatically removes it from the array), but you could not intentionally add them, which was an inconsistency.
You could intentionally add them in the constructor.
If E2 is a statically typed language, then values need to not suddenly stop being members of a certain type because of external changes.
@AbigailBuccaneer null entities are still entities
@Divran yep, we're in agreement (#1538). You're the one who said that you didn't want foreach(K, V:entity = T) to iterate over null entities
nah either way's fine