mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
343 lines
18 KiB
ReStructuredText
343 lines
18 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_Script:
|
||
|
||
Script
|
||
======
|
||
|
||
**Успадковує:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
||
|
||
**Успадковано від:** :ref:`CSharpScript<class_CSharpScript>`, :ref:`GDScript<class_GDScript>`, :ref:`ScriptExtension<class_ScriptExtension>`
|
||
|
||
Клас зберігається як ресурс.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Опис
|
||
--------
|
||
|
||
Клас зберігається як ресурс. Скрипт розширює функціональність всіх об'єктів, які миттєво переходять її.
|
||
|
||
Це базовий клас для всіх скрипти і не слід використовувати безпосередньо. Намагатися створити новий скрипт з цим класом призведе до помилки.
|
||
|
||
\ ``new`` метод скриптового підкласу створює новий екземпляр. :ref:`Object.set_script()<class_Object_method_set_script>` розширює існуючий об'єкт, якщо цей клас відповідає одному з базових класів скриптів.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Посібники
|
||
------------------
|
||
|
||
- :doc:`Індекс написання документації <../tutorials/scripting/index>`
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Властивості
|
||
----------------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-----------------------------+-------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`source_code<class_Script_property_source_code>` |
|
||
+-----------------------------+-------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Методи
|
||
------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`can_instantiate<class_Script_method_can_instantiate>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Script<class_Script>` | :ref:`get_base_script<class_Script_method_get_base_script>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`StringName<class_StringName>` | :ref:`get_global_name<class_Script_method_get_global_name>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`StringName<class_StringName>` | :ref:`get_instance_base_type<class_Script_method_get_instance_base_type>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_property_default_value<class_Script_method_get_property_default_value>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_rpc_config<class_Script_method_get_rpc_config>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Dictionary<class_Dictionary>` | :ref:`get_script_constant_map<class_Script_method_get_script_constant_map>`\ (\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_script_method_list<class_Script_method_get_script_method_list>`\ (\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_script_property_list<class_Script_method_get_script_property_list>`\ (\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_script_signal_list<class_Script_method_get_script_signal_list>`\ (\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_script_signal<class_Script_method_has_script_signal>`\ (\ signal_name\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_source_code<class_Script_method_has_source_code>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`instance_has<class_Script_method_instance_has>`\ (\ base_object\: :ref:`Object<class_Object>`\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_abstract<class_Script_method_is_abstract>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_tool<class_Script_method_is_tool>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`reload<class_Script_method_reload>`\ (\ keep_state\: :ref:`bool<class_bool>` = false\ ) |
|
||
+------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описи властивостей
|
||
------------------------------------
|
||
|
||
.. _class_Script_property_source_code:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`String<class_String>` **source_code** :ref:`🔗<class_Script_property_source_code>`
|
||
|
||
.. rst-class:: classref-property-setget
|
||
|
||
- |void| **set_source_code**\ (\ value\: :ref:`String<class_String>`\ )
|
||
- :ref:`String<class_String>` **get_source_code**\ (\ )
|
||
|
||
Початковий код або порожній рядок, якщо вихідний код не доступний. При налаштуванні автоматично не перезавантажити клас.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описи методів
|
||
--------------------------
|
||
|
||
.. _class_Script_method_can_instantiate:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **can_instantiate**\ (\ ) |const| :ref:`🔗<class_Script_method_can_instantiate>`
|
||
|
||
Повертає ``true``, якщо скрипт може бути миттєвим.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_base_script:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Script<class_Script>` **get_base_script**\ (\ ) |const| :ref:`🔗<class_Script_method_get_base_script>`
|
||
|
||
Повернути скрипт безпосередньо успадкував цей скрипт.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_global_name:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`StringName<class_StringName>` **get_global_name**\ (\ ) |const| :ref:`🔗<class_Script_method_get_global_name>`
|
||
|
||
Повертає назву класу, пов’язану зі сценарієм, якщо вона є. В іншому випадку повертає порожній рядок.
|
||
|
||
Щоб дати сценарію глобальне ім’я, ви можете використати ключове слово ``class_name`` у GDScript і атрибут ``[GlobalClass]`` у C#.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
class_name MyNode
|
||
extends Node
|
||
|
||
.. code-tab:: csharp
|
||
|
||
using Godot;
|
||
|
||
[GlobalClass]
|
||
public partial class MyNode : Node
|
||
{
|
||
}
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_instance_base_type:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`StringName<class_StringName>` **get_instance_base_type**\ (\ ) |const| :ref:`🔗<class_Script_method_get_instance_base_type>`
|
||
|
||
Повернення базового типу скрипта.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_property_default_value:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_property_default_value**\ (\ property\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_Script_method_get_property_default_value>`
|
||
|
||
Повертає значення за замовчуванням вказаного майна.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_rpc_config:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_rpc_config**\ (\ ) |const| :ref:`🔗<class_Script_method_get_rpc_config>`
|
||
|
||
Повертає назви методів зіставлення :ref:`Dictionary<class_Dictionary>` із їхньою конфігурацією RPC, визначеною цим сценарієм.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_script_constant_map:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Dictionary<class_Dictionary>` **get_script_constant_map**\ (\ ) :ref:`🔗<class_Script_method_get_script_constant_map>`
|
||
|
||
Повертає словник, що містить постійні імена та їх значення.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_script_method_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_script_method_list**\ (\ ) :ref:`🔗<class_Script_method_get_script_method_list>`
|
||
|
||
Повертає список методів у цьому ``Script.
|
||
|
||
[b``\ Примітка:** Словники, що повертаються цим методом, відформатовані ідентично тим, що повертаються методом :ref:`Object.get_method_list()<class_Object_method_get_method_list>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_script_property_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_script_property_list**\ (\ ) :ref:`🔗<class_Script_method_get_script_property_list>`
|
||
|
||
Повертає список властивостей у цьому **Script**.
|
||
|
||
\ **Примітка:** Словники, що повертаються цим методом, відформатовані ідентично тим, що повертаються :ref:`Object.get_property_list()<class_Object_method_get_property_list>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_get_script_signal_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_script_signal_list**\ (\ ) :ref:`🔗<class_Script_method_get_script_signal_list>`
|
||
|
||
Returns the list of signals defined in this **Script**.
|
||
|
||
\ **Note:** The dictionaries returned by this method are formatted identically to those returned by :ref:`Object.get_signal_list()<class_Object_method_get_signal_list>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_has_script_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_script_signal**\ (\ signal_name\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Script_method_has_script_signal>`
|
||
|
||
Повертає ``true``, якщо скрипт, або базовий клас, визначає сигнал з вказаною назвою.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_has_source_code:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_source_code**\ (\ ) |const| :ref:`🔗<class_Script_method_has_source_code>`
|
||
|
||
Повертає ``true``, якщо скрипт містить вихідний коду..
|
||
|
||
\ **Примітка:** Якщо скрипт не має початкового коду, це не означає, що він не є недійсним або непристойним. Наприклад, :ref:`GDScript<class_GDScript>`, який був експортований з бінарною токенізацією, не має початкового коду, але все ще бджоли, як очікується, і може бути миттєвим. Це можна перевірити :ref:`can_instantiate()<class_Script_method_can_instantiate>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_instance_has:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **instance_has**\ (\ base_object\: :ref:`Object<class_Object>`\ ) |const| :ref:`🔗<class_Script_method_instance_has>`
|
||
|
||
``true`` якщо ``base_object`` є екземпляром цього сценарію.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_is_abstract:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_abstract**\ (\ ) |const| :ref:`🔗<class_Script_method_is_abstract>`
|
||
|
||
``true``, якщо скрипт є абстрактним скриптом. Анотація скрипта не має конструктора і не може бути миттєвим.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_is_tool:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_tool**\ (\ ) |const| :ref:`🔗<class_Script_method_is_tool>`
|
||
|
||
Повертає ``true``, якщо скрипт є скриптом інструменту. У редакторі можна запустити скрипт інструментів.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Script_method_reload:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **reload**\ (\ keep_state\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_Script_method_reload>`
|
||
|
||
Перезавантажити виконання шаблону. Повертаємо код помилки.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Зазвичай, цей метод перевизначається користувачем, щоб він мав вплив.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Цей метод не має побічних ефектів. Не змінює ніяку змінну екземпляра об'єкта.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Цей метод приймає будь-яке число аргументів після описаних тут.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Цей метод використовується для побудови типів.)`
|
||
.. |static| replace:: :abbr:`static (Цей метод не потребує екземпляра для виклику, його можна викликати безпосередньо за допомогою назви класу.)`
|
||
.. |operator| replace:: :abbr:`operator (Цей метод описує дійсний оператор для взаємодії з цим типом як з лівим операндом.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Це значення є цілим числом, складеним у вигляді бітової маски з наступних прапорів.)`
|
||
.. |void| replace:: :abbr:`void (Значення не повертається.)`
|