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

Console: Difference between revisions

From Official Factorio Wiki
Jump to navigation Jump to search
(→‎How to open the console?: - removed redundant message re: '/c' command prefix)
(Majorly restructured page into categorized example groups. Minor content updates for readability, simplification, and to remove redundancy. All examples still exist but were re-ordered.)
Line 9: Line 9:
In other words: Factorio doesn't need any special cheats, it has a console, which allows you to cheat around any limition, if you know how.
In other words: Factorio doesn't need any special cheats, it has a console, which allows you to cheat around any limition, if you know how.


== How to open the console? ==
= 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".


You open the console by default with the key''' '/' or '~''''. This is the chat window in multiplayer. You need to type '/c' in front of your commands, otherwise it is just a chat message!
== Inputting commands ==


To change that key go into the keyboard control and change "Toggle Lua console" to a useful key.
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 has an inbuilt history. You can use the "cursor-up"-key to repeat or quickly edit and re-issue previous commands.
=== Editing ===
 
The console has an inbuilt history. You can use the "cursor-up"-key to edit/repeat the 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 down below.
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.


== Useful commands (cheats) ==
= Example"cheat" commands =
 
Information for additional commands may be found in the [[Modding|modding-section]]
The 0.12.x updated added a _ to a the majority of the methods and properties.
 
* Remove all enemies from the map
    /c local surface = game.local_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


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


* Check how far the biters have evolved
== Mine faster ==
  /c game.local_player.print(game.evolution_factor)
  /c game.local_player.force.manual_mining_speed_modifier=1000


* Turn off night
== Craft faster ==
  /c game.always_day=true
  /c game.local_player.force.manual_crafting_speed_modifier=1000


* Zoom out to place blueprints, that are bigger than your screen.
== Zoom beyond normal bounds ==
  /c game.local_player.zoom = 0.1
  /c game.local_player.zoom = 0.1


* Kill all biters on the "enemy" force
== Use print() instead of game.local_player.print() ==
  /c game.forces["enemy"].kill_all_units()
[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.local_player.print(text) end


* Add 100 iron plates to your inventory
== Check water level in a pipe ==
  /c game.local_player.insert{name="iron-plate", count=100}
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=6066&p=47758#p47758 Check water level in a pipe] (forums)
Hold cursor over the target pipe and execute:
  /c game.local_player.print(game.local_player.selected.get_liquid().amount)


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


* Add new resource patch
=== Add 100 iron plates to your inventory ===
/c game.local_player.insert{name="iron-plate", count=100}
 
== World Manipulation ==
=== Turn off night ===
/c game.always_day=true
 
=== 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"
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"


Line 67: Line 69:
  end
  end


* Finish research
=== Destroy rocks in sandbox-mode ===
/c for name,technology in pairs(game.local_player.force.technologies) do technology.researched=technology.enabled end
[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.
 
* Mine faster
/c game.local_player.force.manual_mining_speed_modifier=1000
 
* Craft faster
/c game.local_player.force.manual_crafting_speed_modifier=1000
 
* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9020 Switching on peacfulmode]
/c game.peaceful_mode = true
/c game.forces["enemy"].kill_all_units()
 
* Faster research
/c game.local_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.
 
* [http://www.factorioforums.com/forum/viewtopic.php?f=18&t=5686 Destroy rocks in sandbox-mode] (you don't have a player here, so you can't destroy anything)
   /c for _,entity in pairs(game.local_player.surface.find_entities_filtered{
   /c for _,entity in pairs(game.local_player.surface.find_entities_filtered{
         area={{game.local_player.position.x-32, game.local_player.position.y-32},
         area={{game.local_player.position.x-32, game.local_player.position.y-32},
Line 93: Line 79:
   end
   end
you need to center the rock in your vision range
you need to center the rock in your vision range
* [http://www.factorioforums.com/forum/viewtopic.php?f=41&t=5638 Use print() instead of game.local_player.print()]
/c print = function(text) game.local_player.print(text) end




* [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]
=== Generate a section of the world and explore it at the same time ===
[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.local_player.force.chart(game.local_player.surface,{lefttop = {x = -1024, y = -1024}, rightbottom = {x = 1024, y = 1024}})
  /c game.local_player.force.chart(game.local_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.
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.


* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=6066&p=47758#p47758 Check water level in a pipe]
== Enemy/Evolution ==
  /c game.local_player.print(game.local_player.selected.get_liquid().amount)
=== Check how far the biters have evolved ===
/c game.local_player.print(game.evolution_factor)
 
=== Disable evolution & increases pollution evolution ===
[http://www.factorioforums.com/forum/viewtopic.php?f=34&t=10159 Disable evolution, increases pollution evolution instead] (forums)
/c game.mapsettings.enemy_evolution.time_factor = 0.000008 * 0
/c game.mapsettings.enemy_evolution.pollution_factor = 0.00003 * 2
 
=== Kill all biters on the "enemy" force ===
/c game.forces["enemy"].kill_all_units()
 
=== Remove all enemies from the map ===
    /c local surface = game.local_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 ===
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9020 Switching on peaceful mode] (forums)
/c game.peaceful_mode = true
/c game.forces["enemy"].kill_all_units()
 
== 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)
  /c game.local_player.character = game.local_player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}
 
=== Change Player color ===
[http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9028 Player color] (forums)
/c game.local_player.color={g=50,b=200,r=200,a=.9}
 
== Research ==
=== Enable faster research ===
/c game.local_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.


* [http://www.factorioforums.com/forum/viewtopic.php?f=18&t=6633 Enabling technologies]
=== Enabling specific technologies ===
[http://www.factorioforums.com/forum/viewtopic.php?f=18&t=6633 Enabling technologies] (forums)
  /c game.local_player.force.technologies['electric-energy-distribution-1'].researched=true
  /c game.local_player.force.technologies['electric-energy-distribution-1'].researched=true
  /c game.local_player.force.technologies['steel-processing'].researched=true
  /c game.local_player.force.technologies['steel-processing'].researched=true


* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=9028 Player color]
=== Finish research immediately ===
/c game.local_player.color={g=50,b=200,r=200,a=.9}
/c for name,technology in pairs(game.local_player.force.technologies) do technology.researched=technology.enabled end
 
== Get robot count within network ==
[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.


* [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?]
=== Count all '''active robots'''===
Count all '''active robots'''
  /c game.local_player.print(game.local_player.force.get_entitycount("logistic-robot"))
  /c game.local_player.print(game.local_player.force.get_entitycount("logistic-robot"))
  /c game.local_player.print(game.local_player.force.get_entitycount("construction-robot"))
  /c game.local_player.print(game.local_player.force.get_entitycount("construction-robot"))


Count all '''active and inactive robots''' in the network, but misses the ones flying over gaps in coverage:
=== Count all '''active and inactive robots''' in the network, but misses the ones flying over gaps in coverage ===
This is no longer needed because the roboport will give accurate counts.
     /c robots = {};
     /c robots = {};
     roboports = {};
     roboports = {};
Line 160: Line 184:
     end
     end


* [http://www.factorioforums.com/forum/viewtopic.php?f=34&t=10159 Disable evolution, increases pollution evolution instead]
= See also =
/c game.mapsettings.enemy_evolution.time_factor = 0.000008 * 0
/c game.mapsettings.enemy_evolution.pollution_factor = 0.00003 * 2
 
* [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]
/c game.local_player.character = game.local_player.surface.create_entity{name="player", position = {0,0}, force = game.forces.player}
 
 
More commands can be looked up in the [[Modding|modding-section]].
 
== See also ==


* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=7981 Superspeedrun]
* [http://www.factorioforums.com/forum/viewtopic.php?f=5&t=7981 Superspeedrun]

Revision as of 08:56, 29 May 2016


No-building-material-icon.png
This article is a stub, and not comprehensive.
You can help this wiki by expanding it.

The console is the built in interface for lua-commands. It works a bit like any command-line-interface or the java-script-console for your browser.

Basically you can fire here all commands, like from any other lua-program (= Modding). This means you have full access to all in-game-internals.

In other words: Factorio doesn't need any special cheats, it has a console, which allows you to cheat around any limition, if you know how.

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 is just 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.

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.

Example"cheat" commands

Information for additional commands may be found in the modding-section

Use it as calculator

(see Inputting Commands: you can repeat a prior command with the "cursor up"-key!)

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

Mine faster

/c game.local_player.force.manual_mining_speed_modifier=1000

Craft faster

/c game.local_player.force.manual_crafting_speed_modifier=1000

Zoom beyond normal bounds

/c game.local_player.zoom = 0.1

Use print() instead of game.local_player.print()

Use print() instead of game.local_player.print() (forums)

/c print = function(text) game.local_player.print(text) end

Check water level in a pipe

Check water level in a pipe (forums) Hold cursor over the target pipe and execute:

/c game.local_player.print(game.local_player.selected.get_liquid().amount)

Inventory Manipulation

Refill resources (refill oil, iron etc.)

While holding the cursor over a resource in-game

/c game.local_player.selected.amount=7500

Add 100 iron plates to your inventory

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

World Manipulation

Turn off night

/c game.always_day=true

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.local_player.surface;
for y=-2,2 do
 for x=-2,2 do
  surface.create_entity({name="stone", amount=5000, position={game.local_player.position.x+x, game.local_player.position.y+y}})
 end
end

Destroy rocks in sandbox-mode

Destroy rocks in sandbox-mode (forums) - you don't have a player here, so you can't destroy anything.

 /c for _,entity in pairs(game.local_player.surface.find_entities_filtered{
       area={{game.local_player.position.x-32, game.local_player.position.y-32},
           {game.local_player.position.x+32, game.local_player.position.y+32}},
           name="stone-rock"})
 do
   entity.destroy()
 end

you need to center the rock in your vision range


Generate a section of the world and explore it at the same time

Generate a section of the world and explore it at the same time (forums)

/c game.local_player.force.chart(game.local_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.local_player.print(game.evolution_factor)

Disable evolution & increases pollution evolution

Disable evolution, increases pollution evolution instead (forums)

/c game.mapsettings.enemy_evolution.time_factor = 0.000008 * 0
/c game.mapsettings.enemy_evolution.pollution_factor = 0.00003 * 2

Kill all biters on the "enemy" force

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

Remove all enemies from the map

   /c local surface = game.local_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

Switching on peaceful mode (forums)

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

Player Character

Spawn a player character

Custom Scenario: How to spawn a character at a certain point (instead of being in god-mode (forums)

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

Change Player color

Player color (forums)

/c game.local_player.color={g=50,b=200,r=200,a=.9}

Research

Enable faster research

/c game.local_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.local_player.force.technologies['electric-energy-distribution-1'].researched=true
/c game.local_player.force.technologies['steel-processing'].researched=true

Finish research immediately

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

Get robot count within network

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.

Count all active robots

/c game.local_player.print(game.local_player.force.get_entitycount("logistic-robot"))
/c game.local_player.print(game.local_player.force.get_entitycount("construction-robot"))

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

Some interesting cheats or useful commands and tips.
# Preface all console commands with /c in .11.0+

# Set player to white
game.local_player.color = {g=1,b=1,r=1,a=.9}

# remove old player
game.remove_offline_player("username")

# Technology and Recipe unlocking
game.local_player.force.reset_technologies()
game.local_player.force.reset_recipes()
game.local_player.force.enable_all_technologies() # does not research them (see below)
game.local_player.force.enable_all_recipes()
game.local_player.force.research_all_technologies()
game.local_player.force.technologies["technology-name"].researched = true

# cheating
game.local_player.force.manual_mining_speed_modifier = 200
game.local_player.force.manual_crafting_speed_modifier = 200
game.speed = 2
game.freeze_day_time()
game.always_day = true
game.peaceful_mode = true
game.local_player.insert{name="item-name", count=1}