command_line_tutorial.rst 3.7 KB

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