command_line_tutorial.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. Path
  11. ----
  12. It is recommended that your Godot binary be in your PATH environment
  13. variable, so it can be executed easily from any place by typing
  14. ``godot``. You can do so on Linux by placing the Godot binary in
  15. ``/usr/local/bin`` and making sure it is called ``godot``.
  16. Setting the project path
  17. ------------------------
  18. Depending on where your Godot binary is located and what your current
  19. working directory is, you may need to set the path to your project
  20. for any of the following commands to work correctly.
  21. This can be done by giving the path to the ``project.godot`` file
  22. of your project as either the first argument, like this:
  23. ::
  24. user@host:~$ godot path_to_your_project/project.godot [other] [commands] [and] [args]
  25. Or by using the ``--path`` argument:
  26. ::
  27. user@host:~$ godot --path path_to_your_project [other] [commands] [and] [args]
  28. For example, the full command for exporting your game (as explained below) might look like this:
  29. ::
  30. user@host:~$ godot --path path_to_your_project --export my_export_preset_name game.exe
  31. Creating a project
  32. ------------------
  33. Creating a project from the command line can be done by navigating the
  34. shell to the desired place and making a project.godot file.
  35. ::
  36. user@host:~$ mkdir newgame
  37. user@host:~$ cd newgame
  38. user@host:~/newgame$ touch project.godot
  39. The project can now be opened with Godot.
  40. Running the editor
  41. ------------------
  42. Running the editor is done by executing Godot with the ``-e`` flag. This
  43. must be done from within the project directory or a subdirectory,
  44. otherwise the command is ignored and the project manager appears.
  45. ::
  46. user@host:~/newgame$ godot -e
  47. If a scene has been created and saved, it can be edited later by running
  48. the same code with that scene as argument.
  49. ::
  50. user@host:~/newgame$ godot -e scene.tscn
  51. Erasing a scene
  52. ---------------
  53. Godot is friends with your filesystem and will not create extra
  54. metadata files. Use ``rm`` to erase a scene file. Make sure nothing
  55. references that scene or else an error will be thrown upon opening.
  56. ::
  57. user@host:~/newgame$ rm scene.tscn
  58. Running the game
  59. ----------------
  60. To run the game, simply execute Godot within the project directory or
  61. subdirectory.
  62. ::
  63. user@host:~/newgame$ godot
  64. When a specific scene needs to be tested, pass that scene to the command
  65. line.
  66. ::
  67. user@host:~/newgame$ godot scene.tscn
  68. Debugging
  69. ---------
  70. Catching errors in the command line can be a difficult task because they
  71. just fly by. For this, a command line debugger is provided by adding
  72. ``-d``. It works for running either the game or a simple scene.
  73. ::
  74. user@host:~/newgame$ godot -d
  75. ::
  76. user@host:~/newgame$ godot -d scene.tscn
  77. .. _doc_command_line_tutorial_exporting:
  78. Exporting
  79. ---------
  80. Exporting the project from the command line is also supported. This is
  81. especially useful for continuous integration setups. The version of Godot
  82. that is headless (server build, no video) is ideal for this.
  83. ::
  84. user@host:~/newgame$ godot --export "Linux/X11" /var/builds/project
  85. user@host:~/newgame$ godot --export Android /var/builds/project.apk
  86. The platform names recognized by the ``--export`` switch are the same as
  87. displayed in the export wizard of the editor. To get a list of supported
  88. platforms from the command line, try exporting to a non-recognized
  89. platform and the full listing of platforms your configuration supports
  90. will be shown.
  91. To export a debug version of the game, use the ``--export-debug`` switch
  92. instead of ``--export``. Their parameters and usage are the same.
  93. Running a script
  94. ----------------
  95. It is possible to run a simple .gd script from the command line. This
  96. feature is especially useful in large projects, for batch
  97. conversion of assets or custom import/export.
  98. The script must inherit from SceneTree or MainLoop.
  99. Here is a simple example of how it works:
  100. .. code:: python
  101. #sayhello.gd
  102. extends SceneTree
  103. func _init():
  104. print("Hello!")
  105. quit()
  106. And how to run it:
  107. ::
  108. user@host:~/newgame$ godot -s sayhello.gd
  109. Hello!
  110. If no project.godot exists at the path, current path is assumed to be the
  111. current working directory (unless ``-path`` is specified).