只有当变量不是有效的字符串(长度> 0,而不是未定义)时,我才尝试运行代码块。基于this SO post,我认为我做得对,但是每次都会运行。我在这里做错了什么?
if (creep.memory.sourceid ||creep.memory.depositLoc||creep.memory.sourceType)
{
creep.memory.sourceid = getSourceMinWorkers(creep);
creep.memory.sourceType='energy';
creep.memory.depositLoc=getClosestDepositLoc(creep.memory.sourceid,creep.memory.sourceType);
console.log(creep.name," harvesting ",creep.memory.sourceType," at: ",creep.memory.sourceid," depositing at: ",creep.memory.depositLoc);
}
console.log 的输出:
H1_1 harvesting energy at: 81a61f68f5eb4057223b05b2 depositing at: a7633d25d9058f616ab8a0f3
H1_1 harvesting energy at: 1649baad43f736c9fc13d2ad depositing at: a7633d25d9058f616ab8a0f3