Troubling getting ID of a structure.



  • Hey, having trouble with the code below. It's the -> container.id that's always undefined.

                for (let source of sources) {
                    let containers = source.pos.findInRange(FIND_STRUCTURES, 1, {
                        filter: s => s.structureType == STRUCTURE_CONTAINER
                    });
    
                    for (let container in containers) {
                        if (_.some(creepsInRoom, b => (b.memory.containerId == container.id && b.memory.role == 'lorry'))) {
                            continue;
                        } else {
                            name = this.createLorry(30, container.id);
                            break;
                        }
                    }
                }
    

    This code below does almost the same, but here the container.id is never undefined.

            for (let source of sources) {
                let containers = source.pos.findInRange(FIND_STRUCTURES, 1, {
                    filter: s => s.structureType == STRUCTURE_CONTAINER
                });
    
                for (let container of containers) {
                    if (_.some(creepsInRoom, c => c.memory.containerId == container.id && c.memory.role == 'miner')) {
                        continue;
                    } else {
                        name = this.createMiner(source.id, container.id);
                        break;
                    }
                    
                }
            }
    

    Hope someone can help me out, thanks!



  • Looking IN the Array, you are, when looking OF the Array you should.

    IN is for objects. OF is for arrays.



  • Cheers for that!