瀏覽代碼

GDScript style guide: Add comments section, and change quotes (#2868)

* Add section about spacing comments

* Replace single quotes with double quotes
Aaron Franke 5 年之前
父節點
當前提交
1dfb69578c
共有 1 個文件被更改,包括 25 次插入5 次删除
  1. 25 5
      getting_started/scripting/gdscript/gdscript_styleguide.rst

+ 25 - 5
getting_started/scripting/gdscript/gdscript_styleguide.rst

@@ -54,7 +54,7 @@ regular code blocks.
 
 ::
 
-    effect.interpolate_property(sprite, 'transform/scale',
+    effect.interpolate_property(sprite, "transform/scale",
                 sprite.get_scale(), Vector2(2.0, 2.0), 0.3,
                 Tween.TRANS_QUAD, Tween.EASE_OUT)
 
@@ -62,7 +62,7 @@ regular code blocks.
 
 ::
 
-    effect.interpolate_property(sprite, 'transform/scale',
+    effect.interpolate_property(sprite, "transform/scale",
         sprite.get_scale(), Vector2(2.0, 2.0), 0.3,
         Tween.TRANS_QUAD, Tween.EASE_OUT)
 
@@ -131,6 +131,26 @@ necessary for order of operations, they only reduce readability.
     if (is_colliding()):
         queue_free()
 
+Comment spacing
+~~~~~~~~~~~~~~~
+
+Normal comments should start with a space, but comments which are disabled
+code should not. This helps differentiate text comments from disabled code.
+
+**Good**:
+
+::
+
+    # This is a comment.
+    #print("This is disabled code")
+
+**Bad**:
+
+::
+
+    #This is a comment.
+    # print("This is disabled code")
+
 Whitespace
 ~~~~~~~~~~
 
@@ -143,9 +163,9 @@ spaces in dictionary references and function calls, or to create "columns."
 
     position.x = 5
     position.y = mpos.y + 10
-    dict['key'] = 5
+    dict["key"] = 5
     myarray = [4, 5, 6]
-    print('foo')
+    print("foo")
 
 **Bad**:
 
@@ -181,7 +201,7 @@ Also when loading a class into a constant or variable:
 
 ::
 
-    const MyCoolNode = preload('res://my_cool_node.gd')
+    const MyCoolNode = preload("res://my_cool_node.gd")
 
 Functions and variables
 ~~~~~~~~~~~~~~~~~~~~~~~