From 8ffe0b3692779b88ef9f319942640196415e271d Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 8 Feb 2024 20:29:01 +0300 Subject: [PATCH 01/15] docs: Add a paragraph about self. --- .../scripting/gdscript/gdscript_basics.rst | 34 ++++++++++++++++--- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 65588bf0a1f..9096dcee91f 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -185,7 +185,7 @@ in case you want to take a look under the hood. +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | as | Cast the value to a given type if possible. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ -| self | Refers to current class instance. | +| self | See `self`_. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | signal | Defines a signal. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ @@ -1293,9 +1293,9 @@ Functions Functions always belong to a `class `_. The scope priority for variable look-up is: local → class member → global. The ``self`` variable is -always available and is provided as an option for accessing class members, but -is not always required (and should *not* be sent as the function's first -argument, unlike Python). +always available and is provided as an option for accessing class members +(see `self`_), but is not always required (and should *not* be sent as the +function's first argument, unlike Python). :: @@ -1454,6 +1454,32 @@ Here are some examples of expressions:: Identifiers, attributes, and subscripts are valid assignment targets. Other expressions cannot be on the left side of an assignment. +self +"""" + +``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in +current script, however, while may seem surprising, it also allows you to access properties, methods and other names in +subclasses of current script. + +:: + + class_name MyClass extends Node + + func _ready() -> void: + print(self.b) + +``b`` is not defined in ``MyClass``, but we (through, e.g., :doc:`documenting our code `) +can assume that it will exist in subclasses of ``MyClass``. For example: + +:: + + extends MyClass + + var b = "Hello from subclass!" + +Will print "Hello from subclass!" when added to the scene, but if we forgot to define ``b`` or used ``MyClass`` directly, +it would result in an error. + if/else/elif ^^^^^^^^^^^^ From 32b56d841cfe78ea7c2a0fe2fee966e3d767cc88 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 8 Feb 2024 20:38:02 +0300 Subject: [PATCH 02/15] mics: Improve code example. --- tutorials/scripting/gdscript/gdscript_basics.rst | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 9096dcee91f..1e47a72cf2d 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1463,22 +1463,22 @@ subclasses of current script. :: - class_name MyClass extends Node + class_name Weapon extends Node func _ready() -> void: - print(self.b) + print(self.damage) -``b`` is not defined in ``MyClass``, but we (through, e.g., :doc:`documenting our code `) -can assume that it will exist in subclasses of ``MyClass``. For example: +``damage`` is not defined in ``Weapon``, but we (through, e.g., :doc:`documenting our code `) +can assume that it will exist in subclasses of ``Weapon``. For example: :: - extends MyClass + extends Weapon - var b = "Hello from subclass!" + var damage := 10 -Will print "Hello from subclass!" when added to the scene, but if we forgot to define ``b`` or used ``MyClass`` directly, -it would result in an error. +Will print "10" when added to the scene, but if we forgot to define ``damage`` on our subclass or +used ``Weapon`` directly, that would result in an error. if/else/elif ^^^^^^^^^^^^ From acd10e722f56ea22119b66671a77fa979405025d Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:46:52 +0300 Subject: [PATCH 03/15] Apply suggestions from code review Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/scripting/gdscript/gdscript_basics.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 1e47a72cf2d..780aea76927 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1455,11 +1455,11 @@ Identifiers, attributes, and subscripts are valid assignment targets. Other expr an assignment. self -"""" +^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in current script, however, while may seem surprising, it also allows you to access properties, methods and other names in -subclasses of current script. +subclasses of the current script. :: @@ -1468,7 +1468,7 @@ subclasses of current script. func _ready() -> void: print(self.damage) -``damage`` is not defined in ``Weapon``, but we (through, e.g., :doc:`documenting our code `) +``damage`` is not defined in ``Weapon``, but we (through, e.g., :ref:`documenting our code `) can assume that it will exist in subclasses of ``Weapon``. For example: :: From 3dddffaec617686ba8511f2d9557f080e56d8b80 Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Thu, 8 Feb 2024 21:48:50 +0300 Subject: [PATCH 04/15] Apply suggestions from code review Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 780aea76927..29f5891ed53 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1458,7 +1458,7 @@ self ^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -current script, however, while may seem surprising, it also allows you to access properties, methods and other names in +the current script, however, while it may seem surprising, it also allows you to access properties, methods, and other names in subclasses of the current script. :: From c5e5979b9f1da54bcf889c75ab5254844002f9d9 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Thu, 8 Feb 2024 21:55:37 +0300 Subject: [PATCH 05/15] misc: Remove problematic wording. --- tutorials/scripting/gdscript/gdscript_basics.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 29f5891ed53..b462f43400c 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1458,8 +1458,7 @@ self ^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -the current script, however, while it may seem surprising, it also allows you to access properties, methods, and other names in -subclasses of the current script. +the current script, however, it also allows you to access properties, methods, and other names in subclasses of the current script. :: From e7e4ac8358801e720d82b89dfabe69ab6e544443 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Fri, 9 Feb 2024 17:47:47 +0300 Subject: [PATCH 06/15] misc: Move emphasis on self allowing dynamic access in general. --- tutorials/scripting/gdscript/gdscript_basics.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index b462f43400c..bc7690f350d 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1458,7 +1458,9 @@ self ^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -the current script, however, it also allows you to access properties, methods, and other names in subclasses of the current script. +the current script, however, while this is generally considered a bad practice, ``self`` also allows you to access properties, +methods, and other names that are defined dynamically (i.e. are expected to exist in subtypes of the current script, or are +provided using :ref:`_get`). :: @@ -1467,17 +1469,16 @@ the current script, however, it also allows you to access properties, methods, a func _ready() -> void: print(self.damage) -``damage`` is not defined in ``Weapon``, but we (through, e.g., :ref:`documenting our code `) -can assume that it will exist in subclasses of ``Weapon``. For example: +``damage`` is not defined in ``Weapon``, but using ``self`` we can assume that it will exist at runtime. For example: :: - extends Weapon + class_name Pistol extends Weapon var damage := 10 -Will print "10" when added to the scene, but if we forgot to define ``damage`` on our subclass or -used ``Weapon`` directly, that would result in an error. +Here we provide ``damage`` in our subtype of ``Weapon``, therefore it will print "10" when added to the scene, but if +we forgot to define ``damage`` on our subtype or used ``Weapon`` directly, that would result in an error. if/else/elif ^^^^^^^^^^^^ From 22b1ea7dbcd80b1b62de0e3c0326b75548b670a3 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Sat, 2 Mar 2024 13:58:46 +0300 Subject: [PATCH 07/15] docs: Rewrite the example illustrating `self` capabilities & add a warning section. --- .../scripting/gdscript/gdscript_basics.rst | 47 ++++++++++++++----- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index bc7690f350d..2786e838a40 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1458,27 +1458,52 @@ self ^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -the current script, however, while this is generally considered a bad practice, ``self`` also allows you to access properties, -methods, and other names that are defined dynamically (i.e. are expected to exist in subtypes of the current script, or are -provided using :ref:`_get`). +the current script, however, ``self`` also allows you to access properties, methods, and other names that are defined dynamically +(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_get`). :: - class_name Weapon extends Node + class_name Item extends Node - func _ready() -> void: - print(self.damage) + # Returns the expected size an item will take up in player's inventory (or -1 if it cannot be collected). + func get_size() -> int: + var size = get(&"size") + + return size if size else -1 -``damage`` is not defined in ``Weapon``, but using ``self`` we can assume that it will exist at runtime. For example: + # When player touches an item, collect it if it is collectible (i.e. has a `collect` method). + func on_player_touch() -> void: + if has_method(&"collect"): + # collect() # Would be an error! + # self.collect() # An error, too! `self` only bypasses property checks. + call(&"collect") + +``size`` nor ``collect()`` are defined in the base ``Item`` class, but if they are defined at runtime, our code will +react appropriately. For example: :: - class_name Pistol extends Weapon + class_name Potion extends Item + + var size := 2 + + func collect() -> void: + print("Collected a potion!") + +If we call ``get_size`` on our ``Potion``, it will return ``2``, and if we (hypothetically) touch the potion with our +character, we will see "Collected a potion!" in the logs. + +.. warning:: - var damage := 10 + Beware that accessing members of child classes in the base class is often considered a bad practice because this + makes the relationships between parts of your game's code harder to reason about. It is easy to forget to define + a variable that a base class expected, and more complex dependencies between classes cause the code to be + non-self-explanatory. -Here we provide ``damage`` in our subtype of ``Weapon``, therefore it will print "10" when added to the scene, but if -we forgot to define ``damage`` on our subtype or used ``Weapon`` directly, that would result in an error. + The above example isn't ideal too and is exaggerated for illustration purposes. In ``get_size``, instead of querying + for the ``size`` property, we could've instead made it return ``-1`` by default in our base class, and then in our + potion, we would've overridden it to return ``2``. Same for ``collect()`` - we could've defined it in our base class + but made it do nothing by default. Then, the potion subclass would've overridden it to do its own logic. if/else/elif ^^^^^^^^^^^^ From 9fc4324ec9fdb124084cfd3285ba2a1842b20b07 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Sat, 2 Mar 2024 14:00:13 +0300 Subject: [PATCH 08/15] mics: Shorten --- tutorials/scripting/gdscript/gdscript_basics.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 2786e838a40..d5d006b5e58 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1479,9 +1479,7 @@ the current script, however, ``self`` also allows you to access properties, meth call(&"collect") ``size`` nor ``collect()`` are defined in the base ``Item`` class, but if they are defined at runtime, our code will -react appropriately. For example: - -:: +react appropriately. For example:: class_name Potion extends Item From 06769e7d0ad96a97d5b5d34b6e006d0f51c21697 Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Fri, 2 Aug 2024 19:29:29 +0300 Subject: [PATCH 09/15] Update tutorials/scripting/gdscript/gdscript_basics.rst Co-authored-by: RedMser <5117197+RedMser@users.noreply.github.com> --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index d5d006b5e58..e01ce28f07c 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1458,7 +1458,7 @@ self ^^^^ ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -the current script, however, ``self`` also allows you to access properties, methods, and other names that are defined dynamically +the current script. However, ``self`` also allows you to access properties, methods, and other names that are defined dynamically (i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_get`). :: From c6452a1b048d305cbfd2e770edbc739fd70e12f7 Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Wed, 25 Dec 2024 15:00:10 +0300 Subject: [PATCH 10/15] Update tutorials/scripting/gdscript/gdscript_basics.rst Co-authored-by: Danil Alexeev --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index e01ce28f07c..e0ae50c9e01 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1459,7 +1459,7 @@ self ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in the current script. However, ``self`` also allows you to access properties, methods, and other names that are defined dynamically -(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_get`). +(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_set() ` and :ref:`_get() `). :: From 473c81753d0fa8c6489c27b538b22a7970f73aa5 Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Wed, 25 Dec 2024 17:28:04 +0300 Subject: [PATCH 11/15] update --- .../scripting/gdscript/gdscript_basics.rst | 47 ++++++------------- 1 file changed, 14 insertions(+), 33 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 2e64a2e49f8..7f162218a0d 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1535,49 +1535,30 @@ self ``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in the current script. However, ``self`` also allows you to access properties, methods, and other names that are defined dynamically -(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_set() ` and :ref:`_get() `). +(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_set() ` +and/or :ref:`_get() `). :: - class_name Item extends Node - - # Returns the expected size an item will take up in player's inventory (or -1 if it cannot be collected). - func get_size() -> int: - var size = get(&"size") - - return size if size else -1 - - # When player touches an item, collect it if it is collectible (i.e. has a `collect` method). - func on_player_touch() -> void: - if has_method(&"collect"): - # collect() # Would be an error! - # self.collect() # An error, too! `self` only bypasses property checks. - call(&"collect") - -``size`` nor ``collect()`` are defined in the base ``Item`` class, but if they are defined at runtime, our code will -react appropriately. For example:: - - class_name Potion extends Item - - var size := 2 + extends Node - func collect() -> void: - print("Collected a potion!") + func _ready(): + # Compile time error, as `my_var` is not defined in the current class or its ancestors. + print(my_var) + # Checked at runtime, thus may work for dynamic properties or descendant classes. + print(self.my_var) -If we call ``get_size`` on our ``Potion``, it will return ``2``, and if we (hypothetically) touch the potion with our -character, we will see "Collected a potion!" in the logs. + # Compile time error, as `my_func()` is not defined in the current class or its ancestors. + my_func() + # Checked at runtime, thus may work for descendant classes. + self.my_func() .. warning:: Beware that accessing members of child classes in the base class is often considered a bad practice because this makes the relationships between parts of your game's code harder to reason about. It is easy to forget to define - a variable that a base class expected, and more complex dependencies between classes cause the code to be - non-self-explanatory. - - The above example isn't ideal too and is exaggerated for illustration purposes. In ``get_size``, instead of querying - for the ``size`` property, we could've instead made it return ``-1`` by default in our base class, and then in our - potion, we would've overridden it to return ``2``. Same for ``collect()`` - we could've defined it in our base class - but made it do nothing by default. Then, the potion subclass would've overridden it to do its own logic. + a variable that the base class expected or forget about an invariant that the base class assumed to be true when + implementing a function needed by the base class. if/else/elif ~~~~~~~~~~~~ From f19d59b7901b174b7f72e00049304281e3c11dc6 Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Wed, 25 Dec 2024 21:49:07 +0300 Subject: [PATCH 12/15] Update tutorials/scripting/gdscript/gdscript_basics.rst Co-authored-by: Danil Alexeev --- tutorials/scripting/gdscript/gdscript_basics.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 7f162218a0d..fce97453f27 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -180,7 +180,7 @@ in case you want to take a look under the hood. +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | as | Cast the value to a given type if possible. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ -| self | See `self`_. | +| self | Refers to current class instance. See `self`_. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ | super | Resolves the scope of the parent method. See `Inheritance`_. | +------------+---------------------------------------------------------------------------------------------------------------------------------------------------+ From 86355502ef6ff3579404f4a5a766979ee8103aef Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Wed, 25 Dec 2024 22:00:24 +0300 Subject: [PATCH 13/15] update --- tutorials/scripting/gdscript/gdscript_basics.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index fce97453f27..3e4bc623d90 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1555,10 +1555,9 @@ and/or :ref:`_get() `). .. warning:: - Beware that accessing members of child classes in the base class is often considered a bad practice because this - makes the relationships between parts of your game's code harder to reason about. It is easy to forget to define - a variable that the base class expected or forget about an invariant that the base class assumed to be true when - implementing a function needed by the base class. + Beware that accessing members of child classes in the base class is often considered a bad practice, + because this blurs the area of responsibility of any given piece of code, making the overall relationship + between parts of your game harder to reason about. if/else/elif ~~~~~~~~~~~~ From 945bcc99e479f0711f584ade9d68b35f3fea3ccf Mon Sep 17 00:00:00 2001 From: elenakrittik Date: Wed, 25 Dec 2024 22:03:08 +0300 Subject: [PATCH 14/15] update --- tutorials/scripting/gdscript/gdscript_basics.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 3e4bc623d90..61dd219accd 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1557,7 +1557,8 @@ and/or :ref:`_get() `). Beware that accessing members of child classes in the base class is often considered a bad practice, because this blurs the area of responsibility of any given piece of code, making the overall relationship - between parts of your game harder to reason about. + between parts of your game harder to reason about. Besides that, one can simply forget that the parent + class had some expectations about it's descendants. if/else/elif ~~~~~~~~~~~~ From b21181bb556870228907374d1ea05df603dca9ff Mon Sep 17 00:00:00 2001 From: lena <77104725+elenakrittik@users.noreply.github.com> Date: Thu, 26 Dec 2024 13:08:18 +0300 Subject: [PATCH 15/15] Apply suggestions from code review Co-authored-by: tetrapod <145553014+tetrapod00@users.noreply.github.com> --- .../scripting/gdscript/gdscript_basics.rst | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 61dd219accd..78bd59ab14c 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -1533,10 +1533,12 @@ an assignment. self ^^^^ -``self`` can be used to refer to the current instance and is often equivalent to directly referring to symbols available in -the current script. However, ``self`` also allows you to access properties, methods, and other names that are defined dynamically -(i.e. are expected to exist in subtypes of the current class, or are provided using :ref:`_set() ` -and/or :ref:`_get() `). +``self`` can be used to refer to the current instance and is often equivalent to +directly referring to symbols available in the current script. However, ``self`` +also allows you to access properties, methods, and other names that are defined +dynamically (i.e. are expected to exist in subtypes of the current class, or are +provided using :ref:`_set() ` and/or +:ref:`_get() `). :: @@ -1555,10 +1557,11 @@ and/or :ref:`_get() `). .. warning:: - Beware that accessing members of child classes in the base class is often considered a bad practice, - because this blurs the area of responsibility of any given piece of code, making the overall relationship - between parts of your game harder to reason about. Besides that, one can simply forget that the parent - class had some expectations about it's descendants. + Beware that accessing members of child classes in the base class is often + considered a bad practice, because this blurs the area of responsibility of + any given piece of code, making the overall relationship between parts of + your game harder to reason about. Besides that, one can simply forget that + the parent class had some expectations about it's descendants. if/else/elif ~~~~~~~~~~~~