Callbacks



  • Hi, I've played around with this game now, and noticed that the code snippet below does not work. The goal is to recreate the same creep (having same name and body parts):

    ....
    if (creep.suicide() == OK) {
        var res = Game.spawns.Barracks.canCreateCreep(myBody, myName);
        console.log('res', res);
        if (res == OK) {
            Game.spawns.Barracks.createCreep(myBody, myName);
        }
    ...
    

    The "problem" is that the creep still exists as it is killed (being killed) as I get ERR_NAME_EXISTS (-3) error. Wouldn't it be better have it been a callback for these kind of code? Like so...

    creep.suicide(function() {
        // on success (OK)
    }).error(function(response)) {
        // on error response = ERR_...
    });
    

  • Dev Team

    Unfortunately, this is not possible. The game mechanics are tick-based, not event-based. See more info in this article: Understanding game loop, time and ticks.