Xunie
Xunie

Reputation: 465

In Screeps, can I yield the CPU until the next tick?

There is a Game.cpu.halt() function. Is there a Game.cpu.yield() function I can call to suspend execution until the next tick?

It sure would make my webassembly life A LOT easier.

Upvotes: 1

Views: 153

Answers (1)

NameVergessen
NameVergessen

Reputation: 644

If you want to do so to save your CPU that happens all the time. All CPU time left fills a CPU buffer called bucket. The bucket has only a certain capacity and can only be partially accessed, but it allows to save a lot of CPU time for later use.

If you want to stop your current execute you could use: the method Game.cpu.halt() as described in the API.

https://docs.screeps.com/api/#Game.cpu.halt

Upvotes: 3

Related Questions