From 615ec466cf65ad5c0480aa14b3c8401c25c9b591 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 00:40:53 +0530 Subject: [PATCH 01/12] Update scripting_first_script.rst to static type Refactored GDScript code for full static typing compliance --- .../step_by_step/scripting_first_script.rst | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 144e6d1c279..cdb627d8155 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -143,7 +143,7 @@ Add the following code to your script: .. tabs:: .. code-tab:: gdscript GDScript - func _init(): + func _init() -> void: print("Hello, world!") .. code-tab:: csharp C# @@ -157,7 +157,7 @@ Add the following code to your script: Let's break it down. The ``func`` keyword defines a new function named ``_init``. This is a special name for our class's constructor. The engine calls ``_init()`` on every object or node upon creating it in memory, if you define -this function. +this function. The ``-> void`` tells us that there is no return value for this function. .. note:: GDScript is an indent-based language. The tab at the start of the line that says ``print()`` is necessary for the code to work. If you omit @@ -183,8 +183,8 @@ angular speed in radians per second. Add the following after the ``extends Sprit .. tabs:: .. code-tab:: gdscript GDScript - var speed = 400 - var angular_speed = PI + var speed : int = 400 + var angular_speed : float = PI .. code-tab:: csharp C# @@ -196,9 +196,15 @@ but before functions. Every node instance with this script attached to it will have its own copy of the ``speed`` and ``angular_speed`` properties. -.. note:: Angles in Godot work in radians by default, - but you have built-in functions and properties available if you prefer - to calculate angles in degrees instead. +.. note:: + Angles in Godot work in radians by default, + but you have built-in functions and properties available if you prefer + to calculate angles in degrees instead. + + We are taking the speed as ``int`` which can be ``float``. Here, ``: int``/ ``: float`` + are static type castings where we explicitly mention the type of the variable + and what it allows. This is very helpful when calling in-built functions which + only take certain types and behave differently for other types. To move our icon, we need to update its position and rotation every frame in the game loop. We can use the ``_process()`` virtual function of the ``Node`` class. @@ -224,7 +230,7 @@ At the bottom of the script, define the function: .. tabs:: .. code-tab:: gdscript GDScript - func _process(delta): + func _process(delta : float) -> void: rotation += angular_speed * delta .. code-tab:: csharp C# @@ -272,7 +278,7 @@ them. .. tabs:: .. code-tab:: gdscript GDScript - var velocity = Vector2.UP.rotated(rotation) * speed + var velocity : Vector2 = Vector2.UP.rotated(rotation) * speed position += velocity * delta @@ -286,7 +292,7 @@ As we already saw, the ``var`` keyword defines a new variable. If you put it at the top of the script, it defines a property of the class. Inside a function, it defines a local variable: it only exists within the function's scope. -We define a local variable named ``velocity``, a 2D vector representing both a +We define a local variable named ``velocity``, a 2D vector (static type: ``: Vector2``) representing both a direction and a speed. To make the node move forward, we start from the Vector2 class's constant ``Vector2.UP``, a vector pointing up, and rotate it by calling the Vector2 method ``rotated()``. This expression, ``Vector2.UP.rotated(rotation)``, @@ -318,14 +324,14 @@ Here is the complete ``sprite_2d.gd`` file for reference. extends Sprite2D - var speed = 400 - var angular_speed = PI + var speed : int = 400 + var angular_speed : float = PI - func _process(delta): + func _process(delta : float) -> void: rotation += angular_speed * delta - var velocity = Vector2.UP.rotated(rotation) * speed + var velocity : Vector2 = Vector2.UP.rotated(rotation) * speed position += velocity * delta From 73157c1df3fe79cf8eaabf2f5dbdac247ec993b8 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 01:06:37 +0530 Subject: [PATCH 02/12] Update scripting_first_script.rst --- getting_started/step_by_step/scripting_first_script.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index cdb627d8155..cff3b980044 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -197,6 +197,7 @@ instance with this script attached to it will have its own copy of the ``speed`` and ``angular_speed`` properties. .. note:: + Angles in Godot work in radians by default, but you have built-in functions and properties available if you prefer to calculate angles in degrees instead. From 4ecd4a971a4b823af078b4b8afb327f9d1dc1e8b Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:39:56 +0530 Subject: [PATCH 03/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index cff3b980044..b11b33d6c26 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -183,8 +183,8 @@ angular speed in radians per second. Add the following after the ``extends Sprit .. tabs:: .. code-tab:: gdscript GDScript - var speed : int = 400 - var angular_speed : float = PI + var speed: int = 400 + var angular_speed: float = PI .. code-tab:: csharp C# From aa43e2e71f3621a3f1ac0db4ba0ff3b8f409228c Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:41:36 +0530 Subject: [PATCH 04/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index b11b33d6c26..18118476435 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -198,7 +198,7 @@ and ``angular_speed`` properties. .. note:: - Angles in Godot work in radians by default, + Angles in Godot are in radians by default, but you have built-in functions and properties available if you prefer to calculate angles in degrees instead. From 1f405ffa91d53a31009fa877e8906b5dbf5e73ce Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:44:22 +0530 Subject: [PATCH 05/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 18118476435..c6d0022b96f 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -204,7 +204,7 @@ and ``angular_speed`` properties. We are taking the speed as ``int`` which can be ``float``. Here, ``: int``/ ``: float`` are static type castings where we explicitly mention the type of the variable - and what it allows. This is very helpful when calling in-built functions which + and what it allows. This is very helpful when calling built-in functions which only take certain types and behave differently for other types. To move our icon, we need to update its position and rotation every frame in the From a5548bfa4258ef0086ac13939827c50ee1acb0d9 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:44:35 +0530 Subject: [PATCH 06/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index c6d0022b96f..1b8877035ac 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -231,7 +231,7 @@ At the bottom of the script, define the function: .. tabs:: .. code-tab:: gdscript GDScript - func _process(delta : float) -> void: + func _process(delta: float) -> void: rotation += angular_speed * delta .. code-tab:: csharp C# From 89c383427774d9804b885e811ada00da2faec887 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:44:48 +0530 Subject: [PATCH 07/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 1b8877035ac..54e169239ee 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -279,7 +279,7 @@ them. .. tabs:: .. code-tab:: gdscript GDScript - var velocity : Vector2 = Vector2.UP.rotated(rotation) * speed + var velocity: Vector2 = Vector2.UP.rotated(rotation) * speed position += velocity * delta From f2111b9f5a2947c00cd5b7fc14b59ce48d5aa42f Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:45:11 +0530 Subject: [PATCH 08/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 54e169239ee..084ddc760ee 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -325,8 +325,8 @@ Here is the complete ``sprite_2d.gd`` file for reference. extends Sprite2D - var speed : int = 400 - var angular_speed : float = PI + var speed: int = 400 + var angular_speed: float = PI func _process(delta : float) -> void: From 4b762bfb0d43f5b0dc169088797ab0633ede2c42 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:45:26 +0530 Subject: [PATCH 09/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 084ddc760ee..795d55dbb55 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -329,7 +329,7 @@ Here is the complete ``sprite_2d.gd`` file for reference. var angular_speed: float = PI - func _process(delta : float) -> void: + func _process(delta: float) -> void: rotation += angular_speed * delta var velocity : Vector2 = Vector2.UP.rotated(rotation) * speed From 3048ddb4faff18a1fcc0f8f650206730ba350a78 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:45:43 +0530 Subject: [PATCH 10/12] Apply suggestion from @AThousandShips Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 795d55dbb55..5182ae403ad 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -332,7 +332,7 @@ Here is the complete ``sprite_2d.gd`` file for reference. func _process(delta: float) -> void: rotation += angular_speed * delta - var velocity : Vector2 = Vector2.UP.rotated(rotation) * speed + var velocity: Vector2 = Vector2.UP.rotated(rotation) * speed position += velocity * delta From 15db5d0ae60886b35d173a3a07d84ac879fb3733 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 02:53:36 +0530 Subject: [PATCH 11/12] Update scripting_first_script.rst Resolved all the suggestions --- getting_started/step_by_step/scripting_first_script.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index 5182ae403ad..b721213baf4 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -202,10 +202,10 @@ and ``angular_speed`` properties. but you have built-in functions and properties available if you prefer to calculate angles in degrees instead. - We are taking the speed as ``int`` which can be ``float``. Here, ``: int``/ ``: float`` - are static type castings where we explicitly mention the type of the variable - and what it allows. This is very helpful when calling built-in functions which - only take certain types and behave differently for other types. + Here, ``: int`` and ``: float`` are static type castings where we explicitly + mention the type of the variable and what it allows. This is very helpful + when calling built-in functions which only take certain types and behave + differently for other types. To move our icon, we need to update its position and rotation every frame in the game loop. We can use the ``_process()`` virtual function of the ``Node`` class. From e4a82a51658b659965f692bb497ffc3d00214ed5 Mon Sep 17 00:00:00 2001 From: Sriram Ananth <149565123+SriramAnanth2912@users.noreply.github.com> Date: Tue, 9 Sep 2025 19:42:30 +0530 Subject: [PATCH 12/12] Update scripting_first_script.rst --- getting_started/step_by_step/scripting_first_script.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/getting_started/step_by_step/scripting_first_script.rst b/getting_started/step_by_step/scripting_first_script.rst index b721213baf4..cabe528f5bf 100644 --- a/getting_started/step_by_step/scripting_first_script.rst +++ b/getting_started/step_by_step/scripting_first_script.rst @@ -293,7 +293,7 @@ As we already saw, the ``var`` keyword defines a new variable. If you put it at the top of the script, it defines a property of the class. Inside a function, it defines a local variable: it only exists within the function's scope. -We define a local variable named ``velocity``, a 2D vector (static type: ``: Vector2``) representing both a +We define a local variable named ``velocity``, a 2D vector representing both a direction and a speed. To make the node move forward, we start from the Vector2 class's constant ``Vector2.UP``, a vector pointing up, and rotate it by calling the Vector2 method ``rotated()``. This expression, ``Vector2.UP.rotated(rotation)``,