所以我写了这段代码:
manager.getInventoryContents(730, 2, true, (err,inventory,currencies) => {
if (err){
console.log(err)
} else {
console.log("Create order for : " + orderitemname.length + " items.")
var otn = orderitemname.length -1;
while (otn !== -1) {
var li= inventory.length - 1;
while (li !== -1){
if (inventory[li].market_name === orderitemname[otn]){
console.log("Add item to trade " + orderitemname[otn]);
li = li -1;
otn = otn -1;
} else {
console.log("ERR !!! ITEM NOT IN INVENTORY !!! " + orderitemname[otn]);
//Change Order Status To Failed !!
n = n-1;
otn = -1;
li = -1;
}
}
}
}
})
所以发生的事情是该进程多次调用此事件(因为它处于while循环中),并且节点模块忽略它说:
Error: The request is a duplicate and the action has already occurred in the past, ignored this time
那么我有没有办法只调用一次事件,将其保存到变量或其他内容然后多次使用数据?
答案 0 :(得分:0)
您可以将所有内容包装在新的上下文中,并启动您需要的任何变量。然后,可以从回调函数中访问该变量。
这样的事情:
(() => {
let ctx_data = 0;
manager.getInventoryContents(730, 2, true, (err,inventory,currencies) => {
console.log(++ctx_data);
});
})();