In other languages: Deutsch 日本語 한국어 Русский 中文

Console: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(Major overhaul, updated to reflect V0.13)
Line 1: Line 1:
{{Languages}}
{{Languages}}
= Console Overview =
 
<span style="color:#FF0000">NOTE: Many of the below commands will likely only work in version 0.13, and will disable Achievements for the world they are used in. Use with caution. </span>
 
== Console Overview ==
The Factorio console is the built in interface for executing Lua commands within Factorio. It works similarly to any command line interface or the JavaScript console for your browser.
The Factorio console is the built in interface for executing Lua commands within Factorio. It works similarly to any command line interface or the JavaScript console for your browser.


You can essentially fire any command here, just as you would from a Lua program - Factorio [[Mods]] are merely Lua commands. Therefore you don't necessarily need "cheats" per-se, as the console allows you full access to the game's internals. You only need a familiarity with the commands and types, as shown in the below examples and the [[Modding]] section.
You can essentially fire any Lua command here, just as you would from a Lua program - Factorio [[Mods]] are merely Lua commands. Therefore you don't necessarily need "cheats" active per-se, as the console allows you full access to the game's internals. You only need a familiarity with the commands and types, as shown in the below examples and the [[Modding]] section.


= Using the console =
== Using the console ==
== Opening the console ==
=== Opening the console ===
With default key bindings, the console is opened with the ''' '/' or '~'''' keys. Like most others, this key binding may be customized within the Options Menu->Keyboard>"Toggle Lua console".
With default key bindings, the console is opened with the ''' '/' or '~'''' keys. Like most others, this key binding may be customized within the Options Menu->Keyboard>"Toggle Lua console".


== Inputting commands ==
=== Inputting commands ===


The console is also the chat window in multiplayer. You need to type '/c' in front of your commands, otherwise it is just a chat message!
The console is also the chat window in multiplayer. You need to type '/c' in front of your commands, otherwise it will be sent as a chat message. The console has an inbuilt history. You can use the "cursor-up"-key to repeat or quickly edit and re-issue previous commands.
The console has an inbuilt history. You can use the "cursor-up"-key to repeat or quickly edit and re-issue previous commands.


The game ignores newlines when pasting "scriptlets" in the console. This means they can be written in a human readable form in an editor and copy/pasted into the console, making understanding and editing a bit easier.
The game ignores newlines when pasting "scriptlets" in the console. This means they can be written in a human readable form in an editor and copy/pasted into the console, making understanding and editing a bit easier.


On the other hand, if you want to type ''several commands in one line'' you just need to put ';' (semicolon) between the commands - see examples below.
=== Use it as calculator ===
 
= Example"cheat" commands =
Information for additional commands may be found in the [[Modding|modding-section]]


== Use it as calculator ==
(see [[#Inputting commands|Inputting Commands]]: you can repeat a prior command with the "cursor up"-key!)
  /c game.player.print(1234 * 5678)
  /c game.player.print(1234 * 5678)


== Mine faster ==
=== Mine faster ===
  /c game.player.force.manual_mining_speed_modifier=1000
  /c game.player.force.manual_mining_speed_modifier=1000


== Craft faster ==
=== Craft faster ===
  /c game.player.force.manual_crafting_speed_modifier=1000
  /c game.player.force.manual_crafting_speed_modifier=1000


== Enable Loader ==
=== Unlock and Research all Technology ===
/c game.player.force.recipes["loader"].enabled = true
 
/c game.player.force.recipes["fast-loader"].enabled = true
  /c game.player.force.research_all_technologies()
  /c game.player.force.recipes["express-loader"].enabled = true


== Zoom beyond normal bounds ==
Undo this with:
  /c game.player.zoom = 0.1
 
  for _, tech in pairs(game.player.force.technologies) do tech.researched=false end
 
=== Reset any modifiers to default ===
This includes Tech and speed alterations.


== Use print() instead of game.local_player.print() ==
  /c game.player.force.reset()
[http://www.factorioforums.com/forum/viewtopic.php?f=41&t=5638 Use print() instead of game.local_player.print()] (forums)
  /c print = function(text) game.player.print(text) end


== Check water level in a pipe ==
=== Zoom beyond normal bounds ===
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=6066&p=47758#p47758 Check water level in a pipe] (forums)
Note that zooming too far out can cause performance hits. Be careful.
Hold cursor over the target pipe and execute:
 
  /c game.player.print(game.player.selected.fluidbox[1].amount)
  /c game.player.zoom = 0.1


== Inventory Manipulation ==
== Inventory Manipulation ==
=== Refill resources (refill oil, iron etc.) ===
=== Refill resources (refill oil, iron etc.) ===
While holding the cursor over a resource in-game
While holding the cursor over a resource tile in-game
  /c game.player.selected.amount=7500
  /c game.player.selected.amount=7500


=== Add 100 iron plates to your inventory ===
=== Add items to the player's inventory ===
Replace iron-plate with the internal name of the item desired.
 
  /c game.player.insert{name="iron-plate", count=100}
  /c game.player.insert{name="iron-plate", count=100}
=== Cheat mode ===
Allows for infinite free crafting. Disable by replacing true with false.
/c game.player.cheat_mode=true


== World Manipulation ==
== World Manipulation ==
=== Turn off night ===
=== Turn off night ===
Enables eternal day.
  /c game.surfaces[1].always_day=true
  /c game.surfaces[1].always_day=true
=== Change Game Speed ===
0.5 is half speed, 1 is default, 2 is double speed, etc. This can be used for a lot of things like when you know you will have to wait for long periods of time for something to complete. Increasing will decrease performance, be careful.
/c game.speed = X
=== Freeze Time Passage ===
Stops the advancement of the time if true is passed, or unfreezes it if false is passed.
/c game.player.surface.freeze_daytime(BOOL)


=== Add new resource patch ===
=== Add new resource patch ===
Line 70: Line 86:
  end
  end


=== Destroy rocks in sandbox-mode ===
== Enemy/Evolution ==
[http://www.factorioforums.com/forum/viewtopic.php?f=18&t=5686 Destroy rocks in sandbox-mode (forums)] - you don't have a player here, so you can't destroy anything.
=== Check how far the biters have evolved ===
  /c for _,entity in pairs(game.player.surface.find_entities_filtered{
Note that commands that do not start with "/c" do not disable achievements.
        area={{game.player.position.x-32, game.player.position.y-32},
/evolution
            {game.player.position.x+32, game.player.position.y+32}},
            name="stone-rock"})
  do
    entity.destroy()
  end
you need to center the rock in your vision range


=== Set evolution factor ===
Ranges from 0 (new game) to 1.


=== Generate a section of the world and explore it at the same time ===
  /c game.evolution_factor=X
[http://www.factorioforums.com/forum/viewtopic.php?f=14&t=4761&p=44184#p44184 Generate a section of the world and explore it at the same time] (forums)
  /c game.player.force.chart(game.player.surface,{lefttop = {x = -1024, y = -1024}, rightbottom = {x = 1024, y = 1024}})
 
Simply change the bounding box to the size you want and it will generate the map and explore it in that area. Keep In mind that command is telling Factorio to generate 64*64 (4096) chunks so it's going to take a while before all the background entity generation (trees, resources, biters) are placed in the world.
 
== Enemy/Evolution ==
=== Check how far the biters have evolved ===
/c game.player.print(game.evolution_factor)


=== Disable time-based evolution & increases pollution-based evolution ===
=== Disable time-based evolution & increases pollution-based evolution ===
Line 99: Line 103:


=== Kill all biters on the "enemy" force ===
=== Kill all biters on the "enemy" force ===
Note that this will kill only mobile units and worms, spawners will not be killed.
  /c game.forces["enemy"].kill_all_units()
  /c game.forces["enemy"].kill_all_units()


=== Remove all enemies from the map ===
=== Kill all enemies ===
    /c local surface = game.player.surface
This will kill all biters, bases and worms. Anything that is an enemy will be completely destroyed. This only affects enemies in the explored world, so any unexplored parts of the map which still need to be generated will still have enemies.
    for c in surface.get_chunks() do
 
        for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
/c local surface = game.player.surface
            entity.destroy()
for c in surface.get_chunks() do
        end
    for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
        entity.destroy()
     end
     end
  end


=== Enable peaceful mode ===
=== Enable peaceful mode ===
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9020 Switching on peaceful mode] (forums)
Peaceful mode prevents biter attacks until provoked. Substitute false for true to disable.
  /c game.peaceful_mode = true
  /c game.player.surface.peaceful_mode = true
/c game.forces["enemy"].kill_all_units()


== Player Character ==
== Player Character ==
Commands concerning the player directly.
=== Get Player Position ===
Prints coordinates of your current position.
/c game.player.print({"", "(", game.player.position.x, ", ", game.player.position.y, ")"})
=== Teleport player ===
Moves the player to the specified location. You should be able to teleport to a specific player if you obtain their coordinates via them executing the previous command and giving them to you.
/c game.player.teleport({X, Y})
To teleport to the world's origin, use 0,0.
=== Spawn a player character ===
=== Spawn a player character ===
[http://www.factorioforums.com/forum/viewtopic.php?f=18&t=19447&p=124039#p123991 Custom Scenario: How to spawn a character at a certain point (instead of being in god-mode] (forums)
This is useful for escaping god mode. (see [[Console#Enable_god_mode]].) This will spawn a new player at the spawn point of the world, and connect your controls to it.
 
  /c game.player.character = game.player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}
  /c game.player.character = game.player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}


=== Change Player color ===
=== Change Player color ===
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9028 Player color] (forums)
Note that commands that do not start with "/c" do not disable achievements. Replace COLOR with the name of a color.
  /c game.player.color={r=200,g=50,b=200,a=.9}
/color COLOR
 
=== Enable god mode ===
God mode removes your player character allowing you to fly over obstacles and take no damage.
 
Disassociate your controls from the player:
 
  /c game.player.character = nil
 
Then, hover the mouse over the useless player and destroy it by typing:
 
/c game.player.selected.destroy()
 


== Research ==
== Research ==
Line 136: Line 169:
  /c for name,technology in pairs(game.player.force.technologies) do technology.researched=technology.enabled end
  /c for name,technology in pairs(game.player.force.technologies) do technology.researched=technology.enabled end


== Get robot count within network ==
=== Large Screenshots ===
[http://www.factorioforums.com/forum/viewtopic.php?f=18&t=9867&p=78209#p78209 Where can I see how many Robots are in my network?] (forums)


Note that these are no longer needed because the roboport now provides accurate robot counts.
And finally, this is how you would take a large HD screenshot. As usual, replace the X and Y with the values you wish.


=== Count all '''active robots'''===
The file is put into a folder called "script-output", which is located in the same location as the mods folder. These pictures can be quite large.
  /c game.player.print(game.player.force.get_entitycount("logistic-robot"))
 
  /c game.player.print(game.player.force.get_entitycount("construction-robot"))
  /c game.take_screenshot{resolution = {x = XPOS, y = YPOS}}
 
or
 
  /c game.take_screenshot{showgui = true, resolution = {x = XPOS, y = YPOS}}


=== Count all '''active and inactive robots''' in the network, but misses the ones flying over gaps in coverage ===
    /c robots = {};
    roboports = {};
    logistic = 0;
    construction = 0;
    recurse = function(r)
      id = r.position.x .. "," .. r.position.y;
      if (roboports[id] or r.force.name ~= game.player.force.name) then return end;
      roboports[id] = true;
      logistic = logistic + r.getinventory(1).getitemcount("logistic-robot");
      construction = construction + r.getinventory(1).getitemcount("construction-robot");
      ids = {};
      for _, robot in ipairs(game.findentitiesfiltered{area={{r.position.x-50, r.position.y-50}, {r.position.x+50, r.position.y+50}}, name="construction-robot"}) do;
          id = robot.position.x .. "," .. robot.position.y;
          if ((ids[id] or not robots[id]) and robot.force.name == game.player.force.name) then;
            construction = construction + 1;
            ids[id] = true;
            robots[id] = true;
          end;
      end;
      for _, robot in ipairs(game.findentitiesfiltered{area={{r.position.x-50, r.position.y-50}, {r.position.x+50, r.position.y+50}}, name="logistic-robot"}) do;
          id = robot.position.x .. "," .. robot.position.y;
          if ((ids[id] or not robots[id]) and robot.force.name == game.player.force.name) then;
            logistic = logistic + 1;
            ids[id] = true;
            robots[id] = true;
          end;
      end;
      for _, roboport in ipairs(game.findentitiesfiltered{area={{r.position.x-48.5, r.position.y-48.5}, {r.position.x+48.5, r.position.y+48.5}}, name="roboport"}) do;
          recurse(roboport);
      end;
    end;
    p = game.player.character.position;
    roboport = game.findentitiesfiltered{area={{p.x-48.5, p.y-48.5}, {p.x+48.5, p.y+48.5}}, name="roboport"}[1];
    if (roboport) then;
      recurse(roboport);
      game.player.print("Robots in network: Construction:" .. construction .. " Logistic:" .. logistic);
    else;
      game.player.print("Not in range of a roboport.");
    end


= See also =
= See also =


* [http://lua-api.factorio.com/0.13.4/ Factorio API]
* http://lua-api.factorio.com/0.13.10/ - Factorio API, replace the number at the end with the current factorio version.
* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=7981 Superspeedrun]
* [http://www.factorioforums.com/forum/viewtopic.php?f=18&t=4752 The Console: What is it and How do I use it?]
: Some interesting cheats or useful commands and tips.
* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=6942&p=543H57#p54357 Totaly new player -> setting up a game]:
# Preface all console commands with /c in .11.0+
# Set player to white
game.player.color = {g=1,b=1,r=1,a=.9}
# remove old player
game.remove_offline_player("username")
# Technology and Recipe unlocking
game.player.force.reset_technologies()
game.player.force.reset_recipes()
game.player.force.enable_all_technologies() # does not research them (see below)
game.player.force.enable_all_recipes()
game.player.force.research_all_technologies()
game.player.force.technologies["technology-name"].researched = true
# cheating
game.player.force.manual_mining_speed_modifier = 200
game.player.force.manual_crafting_speed_modifier = 200
game.speed = 2
game.freeze_day_time()
game.surfaces[1].always_day = true
game.surfaces[1].peaceful_mode = true
game.player.insert{name="item-name", count=1}

Revision as of 14:32, 25 July 2016


NOTE: Many of the below commands will likely only work in version 0.13, and will disable Achievements for the world they are used in. Use with caution.

Console Overview

The Factorio console is the built in interface for executing Lua commands within Factorio. It works similarly to any command line interface or the JavaScript console for your browser.

You can essentially fire any Lua command here, just as you would from a Lua program - Factorio Mods are merely Lua commands. Therefore you don't necessarily need "cheats" active per-se, as the console allows you full access to the game's internals. You only need a familiarity with the commands and types, as shown in the below examples and the Modding section.

Using the console

Opening the console

With default key bindings, the console is opened with the '/' or '~' keys. Like most others, this key binding may be customized within the Options Menu->Keyboard>"Toggle Lua console".

Inputting commands

The console is also the chat window in multiplayer. You need to type '/c' in front of your commands, otherwise it will be sent as a chat message. The console has an inbuilt history. You can use the "cursor-up"-key to repeat or quickly edit and re-issue previous commands.

The game ignores newlines when pasting "scriptlets" in the console. This means they can be written in a human readable form in an editor and copy/pasted into the console, making understanding and editing a bit easier.

Use it as calculator

/c game.player.print(1234 * 5678)

Mine faster

/c game.player.force.manual_mining_speed_modifier=1000

Craft faster

/c game.player.force.manual_crafting_speed_modifier=1000

Unlock and Research all Technology

/c game.player.force.research_all_technologies()

Undo this with:

for _, tech in pairs(game.player.force.technologies) do tech.researched=false end

Reset any modifiers to default

This includes Tech and speed alterations.

/c game.player.force.reset()

Zoom beyond normal bounds

Note that zooming too far out can cause performance hits. Be careful.

/c game.player.zoom = 0.1

Inventory Manipulation

Refill resources (refill oil, iron etc.)

While holding the cursor over a resource tile in-game

/c game.player.selected.amount=7500

Add items to the player's inventory

Replace iron-plate with the internal name of the item desired.

/c game.player.insert{name="iron-plate", count=100}

Cheat mode

Allows for infinite free crafting. Disable by replacing true with false.

/c game.player.cheat_mode=true

World Manipulation

Turn off night

Enables eternal day.

/c game.surfaces[1].always_day=true

Change Game Speed

0.5 is half speed, 1 is default, 2 is double speed, etc. This can be used for a lot of things like when you know you will have to wait for long periods of time for something to complete. Increasing will decrease performance, be careful.

/c game.speed = X

Freeze Time Passage

Stops the advancement of the time if true is passed, or unfreezes it if false is passed.

/c game.player.surface.freeze_daytime(BOOL)

Add new resource patch

This creates a new 5x5 patch of resources, centered on the player character. For resources other than stone, just change "stone" to "iron-ore", "copper-ore", or "coal"

/c local surface = game.player.surface;
for y=-2,2 do
 for x=-2,2 do
  surface.create_entity({name="stone", amount=5000, position={game.player.position.x+x, game.player.position.y+y}})
 end
end

Enemy/Evolution

Check how far the biters have evolved

Note that commands that do not start with "/c" do not disable achievements.

/evolution

Set evolution factor

Ranges from 0 (new game) to 1.

/c game.evolution_factor=X

Disable time-based evolution & increases pollution-based evolution

/c game.map_settings.enemy_evolution.time_factor = 0
/c game.map_settings.enemy_evolution.pollution_factor = game.map_settings.enemy_evolution.pollution_factor * 2

The "2" at the end of the last command will double the default pollution factor. You can substitute another number to increase (or decrease) the pollution factor further.

Kill all biters on the "enemy" force

Note that this will kill only mobile units and worms, spawners will not be killed.

/c game.forces["enemy"].kill_all_units()

Kill all enemies

This will kill all biters, bases and worms. Anything that is an enemy will be completely destroyed. This only affects enemies in the explored world, so any unexplored parts of the map which still need to be generated will still have enemies.

/c local surface = game.player.surface
for c in surface.get_chunks() do
   for key, entity in pairs(surface.find_entities_filtered({area={{c.x * 32, c.y * 32}, {c.x * 32 + 32, c.y * 32 + 32}}, force= "enemy"})) do
       entity.destroy()
   end
 end


Enable peaceful mode

Peaceful mode prevents biter attacks until provoked. Substitute false for true to disable.

/c game.player.surface.peaceful_mode = true

Player Character

Commands concerning the player directly.

Get Player Position

Prints coordinates of your current position.

/c game.player.print({"", "(", game.player.position.x, ", ", game.player.position.y, ")"})

Teleport player

Moves the player to the specified location. You should be able to teleport to a specific player if you obtain their coordinates via them executing the previous command and giving them to you.

/c game.player.teleport({X, Y})

To teleport to the world's origin, use 0,0.

Spawn a player character

This is useful for escaping god mode. (see Console#Enable_god_mode.) This will spawn a new player at the spawn point of the world, and connect your controls to it.

/c game.player.character = game.player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}

Change Player color

Note that commands that do not start with "/c" do not disable achievements. Replace COLOR with the name of a color.

/color COLOR

Enable god mode

God mode removes your player character allowing you to fly over obstacles and take no damage.

Disassociate your controls from the player:

/c game.player.character = nil

Then, hover the mouse over the useless player and destroy it by typing:

/c game.player.selected.destroy()


Research

Enable faster research

/c game.player.force.laboratory_speed_modifier = 1

1 is normal speed, 2 is double speed 3 is triple etc. I think it goes up to 100.

Enabling specific technologies

Enabling technologies (forums)

/c game.player.force.technologies['electric-energy-distribution-1'].researched=true
/c game.player.force.technologies['steel-processing'].researched=true

Finish research immediately

/c for name,technology in pairs(game.player.force.technologies) do technology.researched=technology.enabled end

Large Screenshots

And finally, this is how you would take a large HD screenshot. As usual, replace the X and Y with the values you wish.

The file is put into a folder called "script-output", which is located in the same location as the mods folder. These pictures can be quite large.

/c game.take_screenshot{resolution = {x = XPOS, y = YPOS}}

or

/c game.take_screenshot{showgui = true, resolution = {x = XPOS, y = YPOS}}


See also