command_line_tutorial.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 little to 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 is 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 is simple, just navigate the
  34. shell to the desired place and just make project.godot file exist, even
  35. if empty.
  36. ::
  37. user@host:~$ mkdir newgame
  38. user@host:~$ cd newgame
  39. user@host:~/newgame$ touch project.godot
  40. That alone makes for an empty Godot project.
  41. Running the editor
  42. ------------------
  43. Running the editor is done by executing godot with the ``-e`` flag. This
  44. must be done from within the project directory, or a subdirectory,
  45. otherwise the command is ignored and the project manager appears.
  46. ::
  47. user@host:~/newgame$ godot -e
  48. If a scene has been created and saved, it can be edited later by running
  49. the same code with that scene as argument.
  50. ::
  51. user@host:~/newgame$ godot -e scene.tscn
  52. Erasing a scene
  53. ---------------
  54. Godot is friends with your filesystem, and will not create extra
  55. metadata files, simply use ``rm`` to erase a file. Make sure nothing
  56. references that scene, or else an error will be thrown upon opening.
  57. ::
  58. user@host:~/newgame$ rm scene.tscn
  59. Running the game
  60. ----------------
  61. To run the game, simply execute Godot within the project directory or
  62. subdirectory.
  63. ::
  64. user@host:~/newgame$ godot
  65. When a specific scene needs to be tested, pass that scene to the command
  66. line.
  67. ::
  68. user@host:~/newgame$ godot scene.tscn
  69. Debugging
  70. ---------
  71. Catching errors in the command line can be a difficult task because they
  72. just fly by. For this, a command line debugger is provided by adding
  73. ``-d``. It works for both running the game or a simple scene.
  74. ::
  75. user@host:~/newgame$ godot -d
  76. ::
  77. user@host:~/newgame$ godot -d scene.tscn
  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, just 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 very 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).