Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
It feels like maybe the earlier tutorials didn't hammer quite enough on the concept of ticks and how the game processes things. When you call spawnCreep, while an object is returned immediately, that doesn't mean your creep has spawned. Nothing in the game happens in the same tick as your code executes. Instead think of it as:
In your tick:
Your code registers intents to do all these actions
After your code has executed:
The backend processes these and changes the game state
In your next tick:
You can see the changed game state and interact with it.
You're trying to stack things together on one tick and not waiting for your intents to process.
I would argue that the API is not completely broken and undocumented, it's just a bit confusing that spawnCreep returns an object. FWIW this is super-useful later down the line, which is why I suspect this inconsistency exists (it's not done like this anywhere else).
What's happening in your case is that you're invalidating the first object by overwriting the spawnCreep intent with a new spawnCreep intent. It doesn't work as a queue. I do agree this could be better documented. It's not completely broken.
So, you can only have 1 "active" intent on each game "object" at a time? I.e. you can only have 1 "spawn" intent active on each "spawn structure". They don't queue up either... is an intent guaranteed to be completed (either success|error) by the start of the next tick or can they take an indeterminate amount of time to complete (kind of like a future?).
And then, the obvious question; how can I know when it's "safe" to call "spawn" again and be sure it won't overwrite my old "spawn" intent? Is there a "hasActiveIntent" flag I can query on different game objects?
How do you "wait for your intent to process"? is there some state I can query?
Everything is synchronous. Both sides generate intents, there's a sync point, all intents are processed, there's a sync point. An intent can fail for a number of reasons - for example if two creeps try to move to the same tile, only one will succeed. If you have two spawns they could both try to spawn in the same tick, and it's possible one wouldn't succeed as the other had "stolen" the energy.
I would recommend not saving the objects, you can pick them up from getObjectsByPrototype next tick if the intent succeeded.
Creeps can do multiple intents in the same tick. For example, you can move and heal. Or move and attack. There's another undocumented problem here where some intents are mutually exclusive and some are not. Hopefully the devs will document this separately for Arena but as far as I understand it's the same as World right now. https://docs.screeps.com/simultaneous-actions.html
In general do _not_ use docs.screeps.com for Arena docs. Again... something that could probably be better. But once you know you know :)
So, something like this seems like a sensible way of keeping track of what resources I've got available each tick without re-issuing intents to game objects that have already received one (and I can think of a way I would encode the more complex edge cases you linked me to later down the line if/when I need to).
This code will spawn up to 4 creeps. Every loop, I get hold of the ids of spawn structures and creeps that I own using map. Then, because I am guaranteed that the previous ticks intents have all been processed, each of these ids can be used once this tick for something, so when I want to use them, I "shift" the id out of the list (so it won't be re-used this tick) and use the object that id relates to for "something".
This seems like a pretty solid starting point for organising my tick code.