I’m trying to send player coordinates to JS from haxe and can’t seem to get it working. I have tried variations of the below code and nothing seems to work.
package arm;
import iron.Trait;
import iron.object.Object;
import iron.object.Transform;
class UpdatePlayerTrait extends iron.Trait {
public function new() {
super();
notifyOnUpdate(function() {
untyped __js__('window.updatePlayer();');// works
untyped __js__('window.updatePlayer('+object.transform.x+');');//doesn't work
});
}
}
another example
package arm;
import iron.Trait;
import iron.object.Object;
import iron.object.Transform;
class UpdatePlayerTrait extends iron.Trait {
public function new() {
super();
notifyOnUpdate(function() {
var test:String = 'window.updatePlayer('+'"'+object.name+'"'+');';
trace(test); // logs window.updatePlayer("Scene");
untyped __js__('$test');//doesn't work
untyped __js__(test);//doesn't work
});
}
}
The browser console is giving the below error at the very end of the kha.js file and is not helpful. The console in blender never seems to output anything. I used the wiki link you provided as a starting point and got both of them to work. As soon as I try to get actual data from the scene to the browser even just a static string it no longer works.
Uncaught SyntaxError: Unexpected end of input
I added another very simple example of just trying to pass the object name through and it also doesn’t work and gives the same error in browser console.