@Shaz That's how javascript works.
If you have a top level variable that is undefined, Javascript reports an error and the game crashes.
If you have an undefined attribute of an object, Javascript, unlike Ruby or Python, is completely fine.
You just can't use methods or attributes of undefined methods or attributes.
For example:
You can't use terrainTag if it's not defined. Even if you try a code
, which is supposed to convert the undefined value to false, JS will throw an error, because terrainTag is not defined.
Of course you can't use
if it's not defined, because undefined is not a function.
However, using
is completely fine even if terrainTag is undefined. This is how JS handles potentially undefined attributes.
What is not fine though is
Code:
$gamePlayer.terrainTag.value
// or
$gamePlayer.terrainTag.setValue ()
if terrainTag is undefined. It will result in a crash.