playerProfile keeps the same data for every user.
dzinks2009 opened this issue · comments
Hello. Me and my friend are trying to do a simple app that would take all the steam64ids from mysql and then use the id in playerProfileRequest.
`var j = schedule.scheduleJob('*/5 * * * * *', function(){
var array = [];
con.query("SELECT * FROM counterStrikeGlobalOffensive", function (err, rows) {
for (var i = 0; i < rows.length; i++) {
console.log(rows[i].steam64ID);
CSGOCli.playerProfileRequest(CSGOCli.ToAccountID(rows[i].steam64ID));
CSGOCli.on("playerProfile", function(profile) {
console.log(profile.account_profiles[0].ranking.rank_id);
return;
});
}
});
return;
});`
This is where my problem begins. When I do console.log(rows[i].steam64ID, it returns all of the ids that are in the mysql. Then I put the id in playerProfileRequest and then when I do console.log(profile), it keeps repeating the same data for each steamid.
Don't spam the GC. Wait until you get a playerProfile
, then call playerProfileRequest
again with the next steam ID you want info on.
Should I set a timeout?
Wait until you get a playerProfile, then call playerProfileRequest again.
Don't use timeouts, use something like https://caolan.github.io/async/docs.html#eachSeries
Could you give me an example of how could I achieve this? I was trying with some of my friends but we're all new to node js so we didn't get anywhere.
Something like this. I haven't tested this code, so your mileage may vary. It's not even the best way to go about it, but it should work. I specifically don't like adding a new callback every time it iterates, but I don't have any time to debug it or make it more efficient. This should help out a bit, though. The idea is that it's similar to forEach
on an array, but because we have asynchronous callbacks, just using forEach
will iterate over the entire array and disregard the asynchronous operations. By using the async
package and the eachSeries
, we don't iterate until callback()
is called from within our last asynchronous operation.
const steamIDs = ["xxxxxxx", "xxxxxxxxxxx"];
async.eachSeries(steamIDs, (steamID, callback) => {
CSGOCli.playerProfileRequest(CSGOCli.ToAccountID(steamID));
CSGOCli.on("playerProfile", function(profile) {
console.log("Player Rank: " + CSGOCli.Rank.getString(profile.account_profiles[0].ranking.rank_id))
callback();
} );
}, (err) => {
// If an error was thrown, err will be set; otherwise, we're done.
});
I keep getting the same info for some reason :/