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.



  • Hello, receive an error.

    0_1595427944173_05cd1131-6c0d-4fa8-b0f0-b73c9f331ed1-image.png

    The code:

    0_1595428018071_525b2e0d-d039-496e-ab4e-12fcc0e66bc5-image.png

    I have defined many methods but game don't like only this.



  • The problem is createCreep instantiates a creep on success. However, the creep doesn't have an id or an entry in runtimeData.

    https://github.com/screeps/engine/blob/4af4cb81da0c796e39e15c4e488f1ba9768d1d8e/src/game/structures.js#L960

    To avoid these errors the fake creep needs a fake id and an entry in runtimeData. Alternatively, we can just not create a fake creep during createCreep. I can't think of any use case requiring the fake Creep, you have to try hard to even find it.



  • So, it means that we can't use logic like this, yes?



  • @silentium_noxe Looping over Game.screeps after calling Spawn.createCreep and accessing any proprety defined here would cause that error. So even simple stuff like .hits would cause the error.

    As for the code: nothing wrong with it, I do it all the time. I recommend running your spawning logic after your creep logic (this helps avoid running out of cpu as well, if you have too many creeps you run out of cpu before you can run your spawning logic, which will intern cause you to spawn fewer creeps).

    You can also iterate over rooms then iterate over Room.find(FIND_MY_CREEPS), rather than all of your creeps all at once.

    Finally if you want to iterate over creeps that are spawning. I personally iterate over my spawns and check the spawning property and access the Creep that way, since there a fewer Spawns than Creeps.