command_line_tutorial.rst 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. .. _doc_command_line_tutorial:
  2. Command line tutorial
  3. =====================
  4. .. highlight:: shell
  5. Some developers like using the command line extensively. Godot is
  6. designed to be friendly to them, so here are the steps for working
  7. entirely from the command line. Given the engine relies on almost no
  8. external libraries, initialization times are pretty fast, making it
  9. suitable for this workflow.
  10. Command line reference
  11. ----------------------
  12. **General options**
  13. +----------------------------+----------------------------------------------------------------------+
  14. | Command | Description |
  15. +----------------------------+----------------------------------------------------------------------+
  16. | ``-h``, ``--help``, ``/?`` | Display the list of command line options. |
  17. +----------------------------+----------------------------------------------------------------------+
  18. | ``--version`` | Display the version string. |
  19. +----------------------------+----------------------------------------------------------------------+
  20. | ``-v``, ``--verbose`` | Use verbose stdout mode. |
  21. +----------------------------+----------------------------------------------------------------------+
  22. | ``--quiet`` | Quiet mode, silences stdout messages. Errors are still displayed. |
  23. +----------------------------+----------------------------------------------------------------------+
  24. **Run options**
  25. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  26. | Command | Description |
  27. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  28. | ``-e``, ``--editor`` | Start the editor instead of running the scene (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  29. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  30. | ``-p``, ``--project-manager`` | Start the project manager, even if a project is auto-detected (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  31. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  32. | ``-q``, ``--quit`` | Quit after the first iteration. |
  33. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | ``-l <locale>``, ``--language <locale>`` | Use a specific locale (<locale> being a two-letter code). See :ref:`doc_locales` for more details. |
  35. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | ``--path <directory>`` | Path to a project (<directory> must contain a 'project.godot' file). |
  37. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | ``-u``, ``--upwards`` | Scan folders upwards for 'project.godot' file. |
  39. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | ``--main-pack <file>`` | Path to a pack (.pck) file to load. |
  41. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | ``--render-thread <mode>`` | Render thread mode ('unsafe', 'safe', 'separate'). See :ref:`Thread Model <class_ProjectSettings_property_rendering/threads/thread_model>` for more details. |
  43. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | ``--remote-fs <address>`` | Remote filesystem (``<host/IP>[:<port>]`` address). |
  45. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | ``--audio-driver <driver>`` | Audio driver. Use ``--help`` first to display the list of available drivers. |
  47. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | ``--video-driver <driver>`` | Video driver. Use ``--help`` first to display the list of available drivers. |
  49. +------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. **Display options**
  51. +-----------------------------+----------------------------------------------------------------------------+
  52. | Command | Description |
  53. +-----------------------------+----------------------------------------------------------------------------+
  54. | ``-f``, ``--fullscreen`` | Request fullscreen mode. |
  55. +-----------------------------+----------------------------------------------------------------------------+
  56. | ``-m``, ``--maximized`` | Request a maximized window. |
  57. +-----------------------------+----------------------------------------------------------------------------+
  58. | ``-w``, ``--windowed`` | Request windowed mode. |
  59. +-----------------------------+----------------------------------------------------------------------------+
  60. | ``-t``, ``--always-on-top`` | Request an always-on-top window. |
  61. +-----------------------------+----------------------------------------------------------------------------+
  62. | ``--resolution <W>x<H>`` | Request window resolution. |
  63. +-----------------------------+----------------------------------------------------------------------------+
  64. | ``--position <X>,<Y>`` | Request window position. |
  65. +-----------------------------+----------------------------------------------------------------------------+
  66. | ``--low-dpi`` | Force low-DPI mode (macOS and Windows only). |
  67. +-----------------------------+----------------------------------------------------------------------------+
  68. | ``--no-window`` | Disable window creation (Windows only). Useful together with ``--script``. |
  69. +-----------------------------+----------------------------------------------------------------------------+
  70. **Debug options**
  71. .. note::
  72. Debug options are only available in the editor and debug export templates
  73. (they require ``debug`` or ``release_debug`` build targets, see
  74. :ref:`doc_introduction_to_the_buildsystem_target` for more details).
  75. +------------------------------+---------------------------------------------------------------------------------------------+
  76. | Command | Description |
  77. +------------------------------+---------------------------------------------------------------------------------------------+
  78. | ``-d``, ``--debug`` | Debug (local stdout debugger). |
  79. +------------------------------+---------------------------------------------------------------------------------------------+
  80. | ``-b``, ``--breakpoints`` | Breakpoint list as source::line comma-separated pairs, no spaces (use %%20 instead). |
  81. +------------------------------+---------------------------------------------------------------------------------------------+
  82. | ``--profiling`` | Enable profiling in the script debugger. |
  83. +------------------------------+---------------------------------------------------------------------------------------------+
  84. | ``--remote-debug <address>`` | Remote debug (``<host/IP>:<port>`` address). |
  85. +------------------------------+---------------------------------------------------------------------------------------------+
  86. | ``--debug-collisions`` | Show collision shapes when running the scene. |
  87. +------------------------------+---------------------------------------------------------------------------------------------+
  88. | ``--debug-navigation`` | Show navigation polygons when running the scene. |
  89. +------------------------------+---------------------------------------------------------------------------------------------+
  90. | ``--frame-delay <ms>`` | Simulate high CPU load (delay each frame by <ms> milliseconds). |
  91. +------------------------------+---------------------------------------------------------------------------------------------+
  92. | ``--time-scale <scale>`` | Force time scale (higher values are faster, 1.0 is normal speed). |
  93. +------------------------------+---------------------------------------------------------------------------------------------+
  94. | ``--disable-render-loop`` | Disable render loop so rendering only occurs when called explicitly from script. |
  95. +------------------------------+---------------------------------------------------------------------------------------------+
  96. | ``--disable-crash-handler`` | Disable crash handler when supported by the platform code. |
  97. +------------------------------+---------------------------------------------------------------------------------------------+
  98. | ``--fixed-fps <fps>`` | Force a fixed number of frames per second. This setting disables real-time synchronization. |
  99. +------------------------------+---------------------------------------------------------------------------------------------+
  100. | ``--print-fps`` | Print the frames per second to the stdout. |
  101. +------------------------------+---------------------------------------------------------------------------------------------+
  102. **Standalone tools**
  103. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  104. | Command | Description |
  105. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  106. | ``-s <script>``, ``--script <script>`` | Run a script. |
  107. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  108. | ``--check-only`` | Only parse for errors and quit (use with ``--script``). |
  109. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  110. | ``--export <target>`` | Export the project using the given export target. Export only main pack if path ends with .pck or .zip (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  111. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  112. | ``--export-debug <target>`` | Like ``--export``, but use debug template (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  113. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  114. | ``--doctool <path>`` | Dump the engine API reference to the given <path> in XML format, merging if existing files are found (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  115. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  116. | ``--no-docbase`` | Disallow dumping the base types (used with ``--doctool``, :ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  117. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  118. | ``--build-solutions`` | Build the scripting solutions (e.g. for C# projects, :ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  119. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  120. | ``--gdnative-generate-json-api`` | Generate JSON dump of the Godot API for GDNative bindings (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  121. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  122. | ``--test <test>`` | Run a unit test. Use ``--help`` first to display the list of tests. (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  123. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  124. | ``--export-pack <preset> <path>`` | Like ``--export``, but only export the game pack for the given preset. The <path> extension determines whether it will be in PCK or ZIP format. |
  125. | | (:ref:`tools <doc_introduction_to_the_buildsystem_tools>` must be enabled). |
  126. +----------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  127. Path
  128. ----
  129. It is recommended that your Godot binary be in your PATH environment
  130. variable, so it can be executed easily from any place by typing
  131. ``godot``. You can do so on Linux by placing the Godot binary in
  132. ``/usr/local/bin`` and making sure it is called ``godot``.
  133. Setting the project path
  134. ------------------------
  135. Depending on where your Godot binary is located and what your current
  136. working directory is, you may need to set the path to your project
  137. for any of the following commands to work correctly.
  138. This can be done by giving the path to the ``project.godot`` file
  139. of your project as either the first argument, like this:
  140. ::
  141. godot path_to_your_project/project.godot [other] [commands] [and] [args]
  142. Or by using the ``--path`` argument:
  143. ::
  144. godot --path path_to_your_project [other] [commands] [and] [args]
  145. For example, the full command for exporting your game (as explained below) might look like this:
  146. ::
  147. godot --path path_to_your_project --export my_export_preset_name game.exe
  148. Creating a project
  149. ------------------
  150. Creating a project from the command line can be done by navigating the
  151. shell to the desired place and making a project.godot file.
  152. ::
  153. mkdir newgame
  154. cd newgame
  155. touch project.godot
  156. The project can now be opened with Godot.
  157. Running the editor
  158. ------------------
  159. Running the editor is done by executing Godot with the ``-e`` flag. This
  160. must be done from within the project directory or a subdirectory,
  161. otherwise the command is ignored and the project manager appears.
  162. ::
  163. godot -e
  164. If a scene has been created and saved, it can be edited later by running
  165. the same code with that scene as argument.
  166. ::
  167. godot -e scene.tscn
  168. Erasing a scene
  169. ---------------
  170. Godot is friends with your filesystem and will not create extra
  171. metadata files. Use ``rm`` to erase a scene file. Make sure nothing
  172. references that scene or else an error will be thrown upon opening.
  173. ::
  174. rm scene.tscn
  175. Running the game
  176. ----------------
  177. To run the game, simply execute Godot within the project directory or
  178. subdirectory.
  179. ::
  180. godot
  181. When a specific scene needs to be tested, pass that scene to the command
  182. line.
  183. ::
  184. godot scene.tscn
  185. Debugging
  186. ---------
  187. Catching errors in the command line can be a difficult task because they
  188. just fly by. For this, a command line debugger is provided by adding
  189. ``-d``. It works for running either the game or a simple scene.
  190. ::
  191. godot -d
  192. ::
  193. godot -d scene.tscn
  194. .. _doc_command_line_tutorial_exporting:
  195. Exporting
  196. ---------
  197. Exporting the project from the command line is also supported. This is
  198. especially useful for continuous integration setups. The version of Godot
  199. that is headless (server build, no video) is ideal for this.
  200. ::
  201. godot --export "Linux/X11" /var/builds/project
  202. godot --export Android /var/builds/project.apk
  203. The preset name must match the name of an export preset defined in the
  204. project's ``export_presets.cfg`` file. If the preset name contains spaces or
  205. special characters (such as "Windows Desktop"), it must be surrounded with quotes.
  206. To export a debug version of the game, use the ``--export-debug`` switch
  207. instead of ``--export``. Their parameters and usage are the same.
  208. To export only a PCK file, use the ``--export-pack`` option followed by the
  209. preset name and output path, with the file extension, instead of ``--export``.
  210. The output path extension determines the package's format, either PCK or ZIP.
  211. .. warning::
  212. When specifying a relative path as the path for `--export`, `--export-debug`
  213. or `--export-pack`, the path will be relative to the directory containing
  214. the ``project.godot`` file, **not** relative to the current working directory.
  215. Running a script
  216. ----------------
  217. It is possible to run a simple ``.gd`` script from the command line.
  218. This feature is especially useful in large projects, e.g. for batch
  219. conversion of assets or custom import/export.
  220. The script must inherit from ``SceneTree`` or ``MainLoop``.
  221. Here is a simple ``sayhello.gd`` example of how it works:
  222. .. code-block:: python
  223. #!/usr/bin/env -S godot -s
  224. extends SceneTree
  225. func _init():
  226. print("Hello!")
  227. quit()
  228. And how to run it:
  229. ::
  230. # Prints "Hello!" to standard output.
  231. godot -s sayhello.gd
  232. If no ``project.godot`` exists at the path, current path is assumed to be the
  233. current working directory (unless ``--path`` is specified).
  234. The first line of ``sayhello.gd`` above is commonly referred to as
  235. a *shebang*. If the Godot binary is in your ``PATH`` as ``godot``,
  236. it allows you to run the script as follows in modern Linux
  237. distributions, as well as macOS:
  238. ::
  239. # Mark script as executable.
  240. chmod +x sayhello.gd
  241. # Prints "Hello!" to standard output.
  242. ./sayhello.gd
  243. If the above doesn't work in your current version of Linux or macOS, you can
  244. always have the shebang run Godot straight from where it is located as follows:
  245. ::
  246. #!/usr/bin/godot -s