1

I've been trying to store local variable's value into Global variable, but that just doesn't seem to work. Any help on this?

var xv = 0;
var yv = 0;

var itemx = firebase.database().ref().child("item").child("xval");
itemx.on('value', function(xvalue){
    xv = xvalue.val(); 
});

var itemy = firebase.database().ref().child("item").child("yval");
itemy.on('value', function(yvalue){
    yv = yvalue.val();
});

var start = graph.grid[aa][bb];
var end = graph.grid[xv][yv];
var result = astar.search(graph, start, end);

I'm unable to fetch the values of variables xv and yv outside the Firebase function.

1 Answer 1

1

you cannot save an object to a variable defined as integer. Declare the variables without initializing them with any value like this and you are good to go.

var xv, yv;

var itemx = firebase.database().ref().child("item").child("xval");
itemx.on('value', function(xvalue){
    xv = xvalue.val(); // it contains an object to view it print on console.
    console.log(xvalue.val())
});

var itemy = firebase.database().ref().child("item").child("yval");
itemy.on('value', function(yvalue){
    yv = yvalue.val();
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.