command_line_tutorial.rst 23 KB

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