Error This creep doesn't exist yet with Store



  • Which shard is affected?

    shard3

    What happened?

    After the game update version 4.0. I tried to use the store prototype instead of the previous carry. But sometimes there are some confusing errors when the code is executed. Like below:

    Error: This creep doesn't exist yet
        at data (<runtime>:37632:19)
        at Object.get [as store] (eval at exports.defineGameObjectProperties (<runtime>:1093:9), <anonymous>:7:62)
        at Object.switch (roles.advanced:17:53)
        at Object.CreepExtension.work (mount.creep:46:62)
        at Object.doing (utils:64:18)
        at Object.module.exports.loop (main:9:13)
        at __mainLoop:1:52
        at __mainLoop:2:3
        at Object.exports.evalCode (<runtime>:16037:76)
    

    The corresponding code as follows:

    // Update status based on its carrying
    Creep.prototype.updateState = () => {
        // Get the first resource
        const resourceType = (Object.keys(this.store).length > 0) ? 
            Object.keys(this.store)[0] : 
            RESOURCE_ENERGY
        // Get its amount
        const resourceAmount = this.store.getUsedCapacity(resourceType)
    
        // ....
    }
    

    What should have happened?

    You can use the following code to fix this problem (this fix has been updated by replying from @fangxm):

    // creep.work() will execute every tick
    Creep.prototype.work = () => {
        if (this.ticksToLive === CREEP_LIFE_TIME) return;
    }
    

    How can we reproduce this?

    You can find the reproduce from @fangxm reply below.



  • Add a title to your post.

    The creep being called may have been created via let c = new Creep() or c.id = "something falsey" or you've totally borked up a prototype somewhere.

    Object.getOwnPropertyDescriptor might be able to help if it's a prototype problem.



  • I have the same problem.

    This seems to happen when a creep is spawned and then immediately get its store in the same tick.

    I have reproduced the problem in the simulator.

    code:

    var n = 1;
    module.exports.loop = function () {
        if(n == 1){
            let spawn = Game.getObjectById('10484812e4326970c56cf6e3');
            spawn.spawnCreep([MOVE], 't');
            let store = Game.creeps['t'].store;
        }
        n = 0;
        return
    }
    

    error:

    Error: This creep doesn't exist yet
        at _:2:118566
        at Object.get [as store]:7:62
        at Object.module.exports.loop:6:37
        at __mainLoop:1:22556
        at eval:2:4
        at Object.r.run:2:151285
    

  • Dev Team

    @fangxm thank you for the report, we'll take a look.


  • Dev Team

    The fix has been deployed, this issue should be fixed now.



  • @o4kapuk Is the problem really solved? I just ran the test code above, but the problem still appears.


  • Dev Team

    @hopgoldy I used @fangxm's repro code because it's referenced in the root post. Just checked again, it does not trigger an exception anymore. If you've found another case, please share the reproduce code and we'll take a look.



  • @o4kapuk But I still have this problem with the code above.



  • I get this error with the tutorial code


  • Dev Team

    @lhocke how to reproduce it?



  • @o4kapuk here's my reproduction. Unfortunately I'm using PureScript and I haven't been able to strip down my code to a minimum, but it definitely triggers an error on the very first tick you spawn (no errors when it's not the first tick of spawn, but it could still get annoying.) I'm guessing that the fix that you implemented is dodgy. Please attach some debugger to the runtime and see what's happening so that this bug can be get rid of!


  • Dev Team

    @arsdragonfly not like I can do something with the code you provided... well, I'll try to build the minimal reproduction code myself.



  • @arsdragonfly Where do your code running? The bug haven't been fixed in the private server.



  • @fangxm @o4kapuk I just quickly checked, the bug doesn't appear in the simulation room, but for the private server it's indeed still broken.