command_line_tutorial.rst 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Creating a project
  17. ------------------
  18. Creating a project from the command line is simple, just navigate the
  19. shell to the desired place and just make an engine.cfg file exist, even
  20. if empty.
  21. ::
  22. user@host:~$ mkdir newgame
  23. user@host:~$ cd newgame
  24. user@host:~/newgame$ touch engine.cfg
  25. That alone makes for an empty Godot project.
  26. Running the editor
  27. ------------------
  28. Running the editor is done by executing godot with the ``-e`` flag. This
  29. must be done from within the project directory, or a subdirectory,
  30. otherwise the command is ignored and the project manager appears.
  31. ::
  32. user@host:~/newgame$ godot -e
  33. If a scene has been created and saved, it can be edited later by running
  34. the same code with that scene as argument.
  35. ::
  36. user@host:~/newgame$ godot -e scene.xml
  37. Erasing a scene
  38. ---------------
  39. Godot is friends with your filesystem, and will not create extra
  40. metadata files, simply use ``rm`` to erase a file. Make sure nothing
  41. references that scene, or else an error will be thrown upon opening.
  42. ::
  43. user@host:~/newgame$ rm scene.xml
  44. Running the game
  45. ----------------
  46. To run the game, simply execute Godot within the project directory or
  47. subdirectory.
  48. ::
  49. user@host:~/newgame$ godot
  50. When a specific scene needs to be tested, pass that scene to the command
  51. line.
  52. ::
  53. user@host:~/newgame$ godot scene.xml
  54. Debugging
  55. ---------
  56. Catching errors in the command line can be a difficult task because they
  57. just fly by. For this, a command line debugger is provided by adding
  58. ``-d``. It works for both running the game or a simple scene.
  59. ::
  60. user@host:~/newgame$ godot -d
  61. ::
  62. user@host:~/newgame$ godot -d scene.xml
  63. Exporting
  64. ---------
  65. Exporting the project from the command line is also supported. This is
  66. specially useful for continuous integration setups. The version of Godot
  67. that is headless (server build, no video) is ideal for this.
  68. ::
  69. user@host:~/newgame$ godot -export "Linux X11" /var/builds/project
  70. user@host:~/newgame$ godot -export Android /var/builds/project.apk
  71. The platform names recognized by the ``-export`` switch are the same as
  72. displayed in the export wizard of the editor. To get a list of supported
  73. platforms from the command line, just try exporting to a non-recognized
  74. platform and the full listing of platforms your configuration supports
  75. will be shown.
  76. To export a debug version of the game, use the ``-export_debug`` switch
  77. instead of ``-export``. Their parameters and usage are the same.
  78. Running a script
  79. ----------------
  80. It is possible to run a simple .gd script from the command line. This
  81. feature is specially useful in very large projects, for batch
  82. conversion of assets or custom import/export.
  83. The script must inherit from SceneTree or MainLoop.
  84. Here is a simple example of how it works:
  85. .. code:: python
  86. #sayhello.gd
  87. extends SceneTree
  88. func _init():
  89. print("Hello!")
  90. quit()
  91. And how to run it:
  92. ::
  93. user@host:~/newgame$ godot -s sayhello.gd
  94. Hello!
  95. If no engine.cfg exists at the path, current path is assumed to be the
  96. current working directory (unless ``-path`` is specified).