StructureLink.transferEnergy(...) shows deprecated warning message



  • Hi!

    • Shard2

    • Link structures working as expected but throwing an obsolete warning message that is not documented and no alternative implementation was provided in the docs.

    So I wrote this function

    function runLinks(room) { let receiver = Game.getObjectById("5a53c31cbba1f86d946a7a09");

    if (receiver) {
        receiver.memory.receiver = true;
    }
    else { return; }
    
    let senders = room.find(FIND_STRUCTURES, function (s) {
        s.structureType == STRUCTURE_LINK
            && !s.memory.receiver
    });
    for (let l of senders) {        
        if (l.energy > 0) {
            l.transferEnergy(receiver);
        }
    }
    

    }

    And the console is flooding with this warning message: Structure*.transferEnergy is considered deprecated and will be removed soon. Please use Creep.withdraw instead.

    The documentation uses the same implementation. I couldn't find any helpful info in google. http://docs.screeps.com/api/#StructureLink.transferEnergy

    Thanks



  • The transferEnergy method is only deprecated when targetting a creep, in that case you should use Creep.withdraw instead.

    In your example this means that you have to replace l.transferEnergy(receiver) with receiver.withdraw(l). Keep in mind that it's still possible to use link.transferEnergy(anotherLink) though.



  • @postcrafter said in StructureLink.transferEnergy(...) shows deprecated warning message:

    receiver.withdraw(l)

    Hi PostCrafter, thank you for the reply,

    Sorry if I was not clear, in my example, both sender and receiver are Links.

    let receiver = Game.getObjectById("5a53c31cbba1f86d946a7a09") <<< StructureLink

    So transferEnergy should not be creating the warning message.