T1MOXA Posted March 7, 2017 Report Posted March 7, 2017 (edited) Hello. I have a small problem...Sometimes the bot crashes with an error "Cannot read property 'player_name' of undefined" Here is my code: bot.on('friendsList', function() { for (var steamID in bot.myFriends) { if(bot.myFriends[steamID] === 2) { bot.getPersonas([steamID], function(getName) { var friendName = getName[steamID].player_name; //Some code }); } } });Where I erred ? Edited March 7, 2017 by T1MOXA Quote
Dr. McKay Posted March 7, 2017 Report Posted March 7, 2017 You're overwriting the value of steamID in your outer loop, which changes the context of the closure. This is confusing, I know. Just do this and it should work: bot.on('friendsList', function() { Object.keys(bot.myFriends).forEach(function(steamID) { if(bot.myFriends[steamID] === 2) { bot.getPersonas([steamID], function(getName) { var friendName = getName[steamID].player_name; //Some code }); } }); }); T1MOXA 1 Quote
T1MOXA Posted March 7, 2017 Author Report Posted March 7, 2017 Thank you, everything works fine Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.