Answer the question
In order to leave comments, you need to log in
How can I make the script wait for the function to complete?
var game = {
users: [{}]
}
game.users[0].steamid = '76561198166206753';
game.users[1].steamid = '76561198166206756';
InventoryParse(game.users[0].steamid, '730');
console.log('Posle: ' + game.users[0].skins); //undefined
function InventoryParse(SteamId, GameId)
{
var rq = require('request');
rq('http://steamcommunity.com/inventory/'+SteamId+'/'+GameId+'/2?l=english', function (error, response, body) {
if (!error && response.statusCode == 200)
{
var json = JSON.parse(body);
for (var i = 0; i < game.users.length; i++) {
if (game.users[i].steamid == SteamId) {
game.users[i].skins = [];
for (var j = 0; j < json.assets.length; j++) {
game.users[i].skins.push(json.assets[j].classid);
}
}
}
console.log('Do: ' + game.users[0].skins); //Главное здесь выводится, а там нет
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question