Get a value of variable inside Console

Hello guys , please i need to get the value of the position of the camera ( the x axis) , but when i put “scene.camera.position.x” in the console i get “is not defined” , how i can acces to this variable ?

this the js code i use :

window.addEventListener(“DOMContentLoaded”, function() {

var canvas = document.getElementById(‘renderCanvas’);
var engine = new BABYLON.Engine(canvas, true);
var createScene = function() {
var scene = new BABYLON.Scene(engine);

var camera1 = new BABYLON.ArcRotateCamera(“Camera”, 0, 0, 0, new BABYLON.Vector3(100, 40, 0), scene);

 return scene;

};

var scene = createScene();

engine.runRenderLoop(function() {
scene.render();
});

window.addEventListener(“resize”, function() {
engine.resize();
});

});

thanks

Try with scene.activeCamera ?

Your camera has a 0 radius, an arcRotateCamera must have a radius so try var camera1 = new BABYLON.ArcRotateCamera(“Camera”, 0, 0, 5, new BABYLON.Vector3(100, 40, 0), scene);

https://doc.babylonjs.com/babylon101/cameras#arc-rotate-camera

thanks , but i get ReferenceError: scene is not defined

thanks for response , but it is not my question , i just need to get any variable inside the scene i created, but i get ReferenceError: scene is not defined

@mixofo - you’ve named your variable “camera1” but you mention that you’re using:

scene.camera.position.x

In this case try using camera1 instead of camera as you should be accessing the variable name.

Here’s some more info on the arcRotateCamera and how you can also override it’s behavior and position it if you need to.

https://doc.babylonjs.com/babylon101/cameras

1 Like

You question

???

thanks , but it is changed nothing , maybe i need to rexplain my real problem , imagine if i create a variable " my_var" inside the windows.addeventListner function , and if i need to get the value of this variable inside the console , normaly i think scene.my_var should work , but it is give me "scene it is not defined "

Is this a Babylon.js question or a Javascript question? As far as I know a Babylon.js scene does not keep a list of variables. Can you make a playground or edit the one I gave to show your problem.

I think it is a Javascript question , but i test everything to get it , and nothing itisn’t working .
I cant make a playground , because i use a separe JS file, with windows.addeventListner method.

thanks for everything

The scene variable is inside the listener’s scope, so you either have to remove the ‘var’, or you have to put ‘var scene’ before the listener and do ‘scene = new BABYLON.Scene(engine)’ in the listener. See: JavaScript Scope

3 Likes

thanks it is working !

1 Like