Search code examples
javascriptscreeps

lookForAt returns undefined


Hi fellow screeps players,

When I try to assign a lookForAt to a variable, it returns undefined.

Even in the console, if I write

creep.room.lookForAt(LOOK_STRUCTURES, 33, 33);

This returns an object with the different structures located in those coordinates. Instead if I use assign it to a variable

var x = creep.room.lookForAt(LOOK_STRUCTURES, 33, 33);

It returns undefined. Any suggestions?


Solution

  • Variable assignment in the console always return undefined. Try for example:

    var x = 4
    

    If this happens in the actual code and not only in the console, there must be an issue outside of what is documented here.

    When sending objects to the console output it is sometimes also smart to serialize it to JSON like this:

    JSON.stringify(Game.creeps[name].room.lookForAt(LOOK_STRUCTURES, 30, 14))