Jelajahi Sumber

Merge pull request #9777 from 0stam/is-not-conversion

Use the newly introduced ``is not`` operator
Max Hilbrunner 11 bulan lalu
induk
melakukan
ff46ea4407
1 mengubah file dengan 7 tambahan dan 1 penghapusan
  1. 7 1
      tutorials/scripting/gdscript/static_typing.rst

+ 7 - 1
tutorials/scripting/gdscript/static_typing.rst

@@ -272,7 +272,12 @@ get full autocompletion on the player variable thanks to that cast.
 
         player.damage()
 
-    or ``assert()`` statement::
+    You can also simplify the code by using the ``is not`` operator::
+
+        if body is not PlayerController:
+            push_error("Bug: body is not PlayerController")
+
+    Alternatively, you can use the ``assert()`` statement::
 
         assert(body is PlayerController, "Bug: body is not PlayerController.")
 
@@ -282,6 +287,7 @@ get full autocompletion on the player variable thanks to that cast.
 
         player.damage()
 
+
 .. note::
 
     If you try to cast with a built-in type and it fails, Godot will throw an error.