瀏覽代碼

Clarify ternary operator in the style guide

In the current style guide, the example for ternary operators includes a "not" in the conditional which is the same text color as the preceding "if" giving the impression that the format for a ternary operation is "[some_value] if not [condition] else [other_value]" which is incorrect, and may be confusing to figure out. I'm new to Godot and I've never used python (which I understand GDScript is based on). My only experience is with c# which I don't believe has a "not" keyword so I was quite confused by this.

This change would remove "not" from the condition to eliminate confusion, and rearrange the values to keep the meaning of the example code the same. Any alternative that removes the "not" would also work.
notPelf 2 年之前
父節點
當前提交
beb5f02422
共有 1 個文件被更改,包括 1 次插入1 次删除
  1. 1 1
      tutorials/scripting/gdscript/gdscript_styleguide.rst

+ 1 - 1
tutorials/scripting/gdscript/gdscript_styleguide.rst

@@ -318,7 +318,7 @@ The only exception to that rule is the ternary operator:
 
 ::
 
-   next_state = "fall" if not is_on_floor() else "idle"
+   next_state = "idle" if is_on_floor() else "fall"
 
 Format multiline statements for readability
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~