Update Game object during tick || Explain order of ops in tutorial



  • Hello!

    This is coming from a complete newbie to Screeps, so this may need to be taken with a grain (or handful) of salt..

    If your code goes something like:

    if (!spawner.isSpawning) { spawner.spawnCreep(body, name, {memory: {role: miner}}); }
    if (!spawner.isSpawning) { spawner.spawnCreep(body, name, {memory: {role: harvester}}); }
    if (!spawner.isSpawning) { spawner.spawnCreep(body, name, {memory: {role: upgrader}}); }
    

    This will not execute as expected. Properties like isSpawning do not update as soon as the spawnCreep function is called successfully. It seems to only be updated after the whole tick is processed. I'm sure this is far easier to maintain and there's a good chance this has been discussed many times, but I wanted to bring it up anyhow since it nearly turned me away from the game before I even finished the tutorial.

    So, as the concept isn't too hard to consider and like I said, has more than likely already been discussed/debated yet ended up where it's at anyway, my true suggestion is simply to explain this within the tutorial. Put it in as a step 6 or even include it as part of automating the spawning process. You could even use my example so as to explain this concept and why when all three can be called successfully, it's only the upgrader that gets created (last in first out).

    Thanks for reading and I hope it's helpful to someone whether it gets addressed somehow or not.

    PS: As to my own experience, I took the time to ask in the Slack help channel and thankfully received very detailed explanations almost immediately. With that said, if you have potential buyers of the game as stoked as I was finding their code which seems logically sound to not execute as expected.. it's a HUGE turn off. With knowing so little about the game and having came across poorly attempted similar concepts, I honestly assumed almost immediately that this was a bug and the game itself with such a fundamental flaw wasn't worth looking into. I'm VERY glad I didn't stop at that.


  • Dev Team

    This behavior is documented in this article - Scripting Basics:

    The goal of a script is to process the current situation within the game and pass orders to your creeps and spawns. Commands are not executed instantly. Rather, the game remembers your commands and executes them later, after all players' scripts have been executed. For more details on this topic, see the article Understanding game loop, time and ticks.

    The link to this article is in the Tutorial section 1 / step 12. We highly recommend to read linked docs articles while you're going through the Tutorial.



  • @artch said in Update Game object during tick || Explain order of ops in tutorial:

    This behavior is documented in this article - Scripting Basics:

    The goal of a script is to process the current situation within the game and pass orders to your creeps and spawns. Commands are not executed instantly. Rather, the game remembers your commands and executes them later, after all players' scripts have been executed. For more details on this topic, see the article Understanding game loop, time and ticks.

    The link to this article is in the Tutorial section 1 / step 12. We highly recommend to read linked docs articles while you're going through the Tutorial.

    Wow, that makes me pretty sad to have missed that..

    Thank you very much for replying and with such detail. I assumed most of the links within the tutorial were a light suggestion or just handy rather than so meaty. That and the focus on such a fundamental concept would have been a bit more "in your face" during the tutorial.

    In either case, I'm happy to take complete responsibility for missing this bit, but I would be curious how many were like me and missed this.

    Thanks again!