1

With the following in memory: (this can be copy/pasted directly into the Memory tab and committed)

    {
    "creeps": {},
    "spawns": {},
    "DEBUG": true,
    "q": {
        "[spawn Spawn1]": [
            [
                [
                    "work",
                    "carry",
                    "carry",
                    "move",
                    "move"
                ],
                "harvester_1",
                {
                    "type": "harvester"
                }
            ],
            [
                [
                    "tough",
                    "attack",
                    "move",
                    "move"
                ],
                "guard2",
                {
                    "type": "guard"
                }
            ],
            [
                [
                    "work",
                    "carry",
                    "carry",
                    "move",
                    "move"
                ],
                "harvester_3",
                {
                    "type": "harvester"
                }
            ],
            [
                [
                    "ranged_attack",
                    "move",
                    "move",
                    "move",
                    "move"
                ],
                "fighter4",
                {
                    "type": "ranged_fighter"
                }
            ],
            [
                [
                    "heal",
                    "heal",
                    "move",
                    "move",
                    "move"
                ],
                "healer5",
                {
                    "type": "healer"
                }
            ]
        ]
    }
}

The following code returns 0:

console.log(Object.keys(Memory.q).length);

When it's obvious that Memory.q in fact holds a reference to a spawning location.

logging just (Memory.q) outputs the [Object object] reference, so I know it exists somewhere.

What am I missing? Or is this just bugged?

4

1 回答 1

1

哎呀。

请记住,整个脚本的每一次滴答都会再次运行。我忘记了。

在我的脚本开始时,我正在初始化 Memory.q = {}; 每个滴答声,所以它正在清空对象然后再次填充它,这就是检查失败的原因。我将初始代码更改为:

if (typeof Memory.q == "undefined") {
    Memory.q = {};
}

干杯!

于 2014-11-21T23:52:32.147 回答