createCreep called twice in same Game.tick weird



  • Hi,

    I coded some rules to generate creeps in a certain order, and was expecting this behavior:
    createCreep(combination1); // cost higher, if not enough energy it is not a problem, second line will spawn a smaller version
    createCreep(combination2); // cost less, fallback system, expect to be harmless if we have already asked to create a creep on previous line so I should get ERR_BUSY

    In facts, it seems that this is always the latest that is taken into account and it overrides my creation request, so I had to inverse the logic for creation. But programmatically it leads to something not very intuitive. Am I doing something wrong?



  • To understand the game loop better you should read this article: http://support.screeps.com/hc/en-us/articles/203032752-Understanding-game-loop-time-and-ticks.

    Furthermore, for your specific case you should check with canCreateCreep (http://support.screeps.com/hc/en-us/articles/203016392-Spawn#createCreep) if you'll be able to spawn it.



  • Consider calculating the amount of available energy beforehand yourself in order to avoid a wasted costly call. You could iterate over all your spawns and extensions and count their energy but it is even less CPU intense to just report all energy transfers and keep the result of that in memory. If you use hardcoded bodies you know their cost, store them together and compare that to the amount of energy stored.



  • Ok, I get it now, thank you for the reminder, it's not a bug then.