Browse Source

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

Use the newly introduced ``is not`` operator
Max Hilbrunner 11 months ago
parent
commit
ff46ea4407
1 changed files with 7 additions and 1 deletions
  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()
         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.")
         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()
         player.damage()
 
 
+
 .. note::
 .. note::
 
 
     If you try to cast with a built-in type and it fails, Godot will throw an error.
     If you try to cast with a built-in type and it fails, Godot will throw an error.