Jump to content
McKay Development

Async problems using "getUserInventoryContents"


MrKirby

Recommended Posts

I am having issues with calling this function. I think it has something to do with the function waiting a little while. I have searched for callback etc. on the internet and I found a lot but I have no clue how to use them on the code...

 

Question

How do I use sync callback on the function: "getUserInventoryContents"

 

This is what I have now:

manager.getUserInventoryContents(config.accounts.steamid64[i],753, 6, true, (err, inventory) => {
    if (err) {
        console.log(err);
        return;
    } else if (err == null) {
    //The rest of the code				

I thought that this would work... I am not the best in node, basically just started... but hope you could help me :)

Link to comment
Share on other sites

Synchronous I/O functions are contrary to Node's paradigm and so aren't supported. Or is that not what you're asking?

Thanks for the quick response, but it is not what I am looking for, I think.

Whenever it is busy 'getting' a user's inventory, it should freeze a code block (like a normal callback function could do).

But I have no clue on how to run a callback on the "getUserInventoryContents" functoin. 

 

EDIT:

var j = 10;
for(var i=0;i<j;i++) {
console.log("testing... " + i)
manager.getUserInventoryContents(config.accounts.steamid64[i],753, 6, true, (err, inventory) => {
	if (err) {
		console.log(err);
		return;
	} else if (err == null ) {
						
        console.log("Inventory length bot " +inventory.length+" | steamID "+ config.accounts.steamid64[i]);
        //etc. etc.

This will output: 

testing... 0
testing... 1
testing... 2
etc.
testing... 9
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
etc.
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
Inventory length bot 100 | steamID 12345678901234567890 //random ID

Now, how can I make it output this:

testing... 0
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
testing... 1
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
testing... 2
Inventory length bot 100 | steamID 12345678901234567890 //random ID 
etc.

Thanks in advance :)

Edited by MrKirby
Link to comment
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...