MoeJoe111 Posted October 16, 2019 Report Posted October 16, 2019 (edited) Hello,i have a problem with multiple TradeOfferManagers, in this example the first console.log returns a name for a different account then the second console.log. How is this possible? let offer = managers[x].createOffer(new SteamID(steamId), token); offer.getUserDetails((err, me, them) => { console.log(me.personaName); console.log(managers[x].steamID.getSteamID64()); Edited October 17, 2019 by MoeJoe111 Quote
Dr. McKay Posted October 17, 2019 Report Posted October 17, 2019 I would assume this is because the x variable has a larger scope and it has since changed. As an example: for (var i = 0; i < 10; i++) { console.log(i); setTimeout(() => console.log(i), 1000); } This would output: 0 1 2 3 4 5 6 7 8 9 // 1 second delay 10 10 10 10 10 10 10 10 10 10 This is because the i variable changes every time the loop increments, and the callback functions reference that variable with its current value when they execute, not with the value it had when the callback was set up. You can work around this by using let instead of var, which will do what you expect. Quote
MoeJoe111 Posted October 17, 2019 Author Report Posted October 17, 2019 My bad, i should have explained the surrounding code. The idea is to trade items to the bot with the least amount of items in the inventory. I have a function which will return the index of the TradeOfferManager from the account with the least amount of items, which works 100%. The TradeOffer gets sent without any error, but from a different TradeOfferManager than planned. Is it a problem that these TradeOfferManagers use the same SteamCommunity instance? let x = getTradeOfferManagerIndex(); console.log(x); //correct index let manager = managers[x]; console.log(managers[x].steamID.getSteamID64()); //confirmed bot with least amount of items let offer = managers[x].createOffer(new SteamID(steamId), token); offer.getUserDetails((err, me, them) => { console.log(me.personaName); //steamname of a different bot console.log(managers[x].steamID.getSteamID64()); //still correct steamId //... }); //user gets offer from the bot with me.personaName Quote
Dr. McKay Posted October 17, 2019 Report Posted October 17, 2019 Is it a problem that these TradeOfferManagers use the same SteamCommunity instance? Yes. That's not supported. Each TradeOfferManager needs its own SteamCommunity instance. Quote
MoeJoe111 Posted October 17, 2019 Author Report Posted October 17, 2019 Thanks, Problem solved. 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.