It seems you can't instantiate a instance of a custom class outside of the event functions. Doing so results in the error: Undefined variable "{0}". However you can instantiate a new copy of a class such as YVector3 outside of the event functions.
var x =newTest();var p;var v =newYVector3(0,1,0);function onSwitchOn(triggerEntity){
p =newTest();YEntity.spawnEntity(YEntityType.get(35),1, v, v);YDebug.localConsole(p.doSomething());}classTest{constructor(){}
doSomething(){return"test";}}
var x gives the undefined variable error when loading the script
var p has no errors and setting the variable in the onSwitchOn function gives no errors
It seems you can't instantiate a instance of a custom class outside of the event functions. Doing so results in the error: Undefined variable "{0}". However you can instantiate a new copy of a class such as YVector3 outside of the event functions.
-
var x gives the undefined variable error when loading the script
-
var p has no errors and setting the variable in the onSwitchOn function gives no errors
-
var v has no errors
Edited by Shadow72Share this post
Link to post
Share on other sites