Jump to content
McKay Development

Recommended Posts

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 by MoeJoe111

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...