It produces this message:
MissingFieldException: Field ‘NetworkLevelLoad[ ].length’ not found.
Why? As it is run from within NetworkLevelLoad, there must always be one, so the array should always be there… why does NetworkLevelLoad[ ] not have “length” (all of a sudden, this worked before!)?
The workaround is casting it into a different type of array:
if((FindObjectsOfType(NetworkLevelLoad) as Object[]).length > 1)
But this is quite ugly and hard to read. Does anyone get why this happens?
“Length” rather than “length”. “length” is only for dynamic Javascript arrays I believe (in order to conform with “normal” Javascript conventions); “Length” is for everything else.
Ooh… so do I get it right, that depending on the returned type it’s length or Length? Isn’t that a serious problem with dynamic typing, if suddenly at runtime it changes? … talk about messed up polymorphy…
But thanks! That’ll still clean up my code for now
Eh? No, it’s “length” in one case and “Length” for the others, which doesn’t “suddenly change” or cause any problems, aside from the confusion of having both terms. (IMO it ought to have been “Length” for everything, and to heck with “normal” Javascript conventions since Unityscript is different enough in a lot of other ways, but it’s too late now. )