The main global game object containing all the game play information.
A hash containing all your construction sites with their id as hash keys.
An object containing information about your CPU usage with the following properties:
parameter | type | description |
---|---|---|
limit | number | Your assigned CPU limit for the current shard. |
tickLimit | number | An amount of available CPU time at the current game tick. |
bucket | number | An amount of unused CPU accumulated in your bucket. |
shardLimits | object <string,number> | An object with limits for each shard with shard names as keys. You can use |
unlocked | boolean | Whether full CPU is currently unlocked for your account. |
unlockedTime | number | The time in milliseconds since UNIX epoch time until full CPU is unlocked for your account. This property is not defined when full CPU is not unlocked for your account or it's unlocked with a subscription. |
for(const i in Game.creeps) {
Game.creeps[i].moveTo(flag);
}
A hash containing all your creeps with creep names as hash keys.
creep.moveTo(Game.flags.Flag1);
A hash containing all your flags with flag names as hash keys.
Your Global Control Level, an object with the following properties :
parameter | type | description |
---|---|---|
level | number | The current level. |
progress | number | The current progress to the next level. |
progressTotal | number | The progress required to reach the next level. |
Your Global Power Level, an object with the following properties :
parameter | type | description |
---|---|---|
level | number | The current level. |
progress | number | The current progress to the next level. |
progressTotal | number | The progress required to reach the next level. |
A global object representing world map. See the documentation below.
A global object representing the in-game market. See the documentation below.
Game.powerCreeps['PC1'].moveTo(flag);
A hash containing all your power creeps with their names as hash keys. Even power creeps not spawned in the world can be accessed here.
An object with your global resources that are bound to the account, like pixels or cpu unlocks. Each object key is a resource constant, values are resources amounts.
A hash containing all the rooms available to you with room names as hash keys. A room is visible if you have a creep or an owned structure in it.
An object describing the world shard where your script is currently being executed in.
parameter | type | description |
---|---|---|
name | string | The name of the shard. |
type | string | Currently always equals to |
ptr | boolean | Whether this shard belongs to the PTR. |
for(const i in Game.spawns) {
Game.spawns[i].createCreep(body);
}
A hash containing all your spawns with spawn names as hash keys.
A hash containing all your structures with structure id as hash keys.
console.log(Game.time);
System game tick counter. It is automatically incremented on every tick. Learn more
let heap = Game.cpu.getHeapStatistics();
console.log(`Used ${heap.total_heap_size} / ${heap.heap_size_limit}`);
This method is only available when Virtual machine is set to Isolated in your account runtime settings.
Use this method to get heap statistics for your virtual machine. The return value is almost identical to the Node.js function v8.getHeapStatistics()
. This function returns one additional property: externally_allocated_size
which is the total amount of currently allocated memory which is not included in the v8 heap but counts against this isolate's memory limit. ArrayBuffer
instances over a certain size are externally allocated and will be counted here.
Returns an objects with heap statistics in the following format:
{
"total_heap_size": 29085696,
"total_heap_size_executable": 3670016,
"total_physical_size": 26447928,
"total_available_size": 319649520,
"used_heap_size": 17493824,
"heap_size_limit": 343932928,
"malloced_memory": 8192,
"peak_malloced_memory": 1060096,
"does_zap_garbage": 0,
"externally_allocated_size": 38430000
}
if(Game.cpu.getUsed() > Game.cpu.tickLimit / 2) {
console.log("Used half of CPU already!");
}
for(const name in Game.creeps) {
const startCpu = Game.cpu.getUsed();
// creep logic goes here
const elapsed = Game.cpu.getUsed() - startCpu;
console.log('Creep '+name+' has used '+elapsed+' CPU time');
}
Get amount of CPU time used from the beginning of the current game tick. Always returns 0 in the Simulation mode.
Returns currently used CPU time as a float number.
Game.cpu.halt();
This method is only available when Virtual machine is set to Isolated in your account runtime settings.
Reset your runtime environment and wipe all data in heap memory.
Game.cpu.setShardLimits({shard0: 20, shard1: 10});
Allocate CPU limits to different shards. Total amount of CPU should remain equal to
Game.cpu.shardLimits
. This method can be used only once per 12 hours.
parameter | type | description |
---|---|---|
limits | object<string, number> | An object with CPU values for each shard in the same format as |
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_BUSY | -4 | 12-hours cooldown period is not over yet. |
ERR_INVALID_ARGS | -10 | The argument is not a valid shard limits object. |
if(Game.cpu.unlockedTime && ((Game.cpu.unlockedTime - Date.now()) < 1000*60*60*24)) {
Game.cpu.unlock();
}
Unlock full CPU for your account for additional 24 hours. This method will consume 1 CPU unlock bound to your account (See Game.resources
).
If full CPU is not currently unlocked for your account, it may take some time (up to 5 minutes) before unlock is applied to your account.
One of the following codes:
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_ENOUGH_RESOURCES | -6 | Your account does not have enough |
ERR_FULL | -8 | Your CPU is unlocked with a subscription. |
if(Game.cpu.bucket == 10000) {
Game.cpu.generatePixel();
}
Generate 1 pixel resource unit for 10000 CPU from your bucket.
constant | value | description |
---|---|---|
OK | 0 | The operation has been scheduled successfully. |
ERR_NOT_ENOUGH_RESOURCES | -6 | Your bucket does not have enough CPU. |
creep.memory.sourceId = creep.pos.findClosestByRange(FIND_SOURCES).id;
const source = Game.getObjectById(creep.memory.sourceId);
Get an object with the specified unique ID. It may be a game object of any type. Only objects from the rooms which are visible to you can be accessed.
parameter | type | description |
---|---|---|
id | string | The unique identificator. |
Returns an object instance or null if it cannot be found.
if(creep.hits < creep.memory.lastHits) {
Game.notify('Creep '+creep+' has been attacked at '+creep.pos+'!');
}
creep.memory.lastHits = creep.hits;
if(Game.spawns['Spawn1'].energy == 0) {
Game.notify(
'Spawn1 is out of energy',
180 // group these notifications for 3 hours
);
}
Send a custom message at your profile email. This way, you can set up notifications to yourself on any occasion within the game. You can schedule up to 20 notifications during one game tick. Not available in the Simulation Room.
parameter | type | description |
---|---|---|
message | string | Custom text which will be sent in the message. Maximum length is 1000 characters. |
groupInterval | number | If set to 0 (default), the notification will be scheduled immediately. Otherwise, it will be grouped with other notifications and mailed out later using the specified time in minutes. |