Merge class_name docs from scripting_continued.rst into gdscript docs

This commit is contained in:
Nathan Lovato
2020-11-07 23:23:19 -06:00
parent 47b0008cc0
commit 5a21563707
7 changed files with 12 additions and 51 deletions

View File

@@ -190,7 +190,7 @@ those values and saves the resource, the Inspector serializes the custom propert
too! To save a resource from the Inspector, click the Inspector's tools menu (top right),
and select "Save" or "Save As...".
If the script's language supports :ref:`script classes <doc_scripting_continued_class_name>`,
If the script's language supports :ref:`script classes <doc_gdscript_basics_class_name>`,
then it streamlines the process. Defining a name for your script alone will add it to
the Inspector's creation dialog. This will auto-add your script to the Resource
object you create.

View File

@@ -5,12 +5,9 @@ Scripting (continued)
Notifications
-------------
Godot has a system of notifications. These are usually not needed for
Godot has a low-level notifications system. You don't are usually not needed for
scripting, as it's too low-level and virtual functions are provided for
most of them. It's just good to know they exist. For example,
you may add an
:ref:`Object._notification() <class_Object_method__notification>`
function in your script:
most of them. You can learn more about how notifications work under the hood in :ref:`doc_godot_notifications`.
.. tabs::
.. code-tab:: gdscript GDScript
@@ -119,42 +116,3 @@ follows, can be applied to nodes:
base._PhysicsProcess(delta);
}
As mentioned before, it's better to use these functions instead of
the notification system.
.. _doc_scripting_continued_class_name:
Register scripts as classes
---------------------------
Godot has a "Script Class" feature to register individual scripts with the
Editor. By default, you can only access unnamed scripts by loading the file
directly.
You can name a script and register it as a type in the editor with the
``class_name`` keyword followed by the class's name. You may add a comma and an
optional path to a PNG or SVG image to use as an icon (16×16 minimum, 32×32 recommended).
You will then find your new type in the Node or Resource creation dialog.
Note that the icon will only appear after restarting the editor.
.. tabs::
.. code-tab:: gdscript GDScript
extends Node
# Declare the class name here
class_name ScriptName, "res://path/to/optional/icon.svg"
func _ready():
var this = ScriptName # reference to the script
var cppNode = MyCppNode.new() # new instance of a class named MyCppNode
cppNode.queue_free()
.. image:: img/script_class_nativescript_example.png
.. warning:: In Godot 3.1:
- Only GDScript and NativeScript, i.e., C++ and other GDNative-powered languages, can register scripts.
- Only GDScript creates global variables for each named script.

View File

@@ -68,7 +68,7 @@ or data across many scenes.
In the case of functions, you can create a new type of ``Node`` that provides
that feature for an individual scene using the :ref:`class_name
<doc_scripting_continued_class_name>` keyword in GDScript.
<doc_gdscript_basics_class_name>` keyword in GDScript.
When it comes to data, you can either:

View File

@@ -112,7 +112,7 @@ There are two systems for registering types...
- Set up using :ref:`EditorPlugin.add_custom_type <class_EditorPlugin_method_add_custom_type>`.
- :ref:`Script Classes <doc_scripting_continued_class_name>`
- :ref:`Script Classes <doc_gdscript_basics_class_name>`
- Editor and runtime accessible.

View File

@@ -138,7 +138,7 @@ custom behavior.
Nodes added via an EditorPlugin are "CustomType" nodes. While they work
with any scripting language, they have fewer features than
:ref:`the Script Class system <doc_scripting_continued_class_name>`. If you
:ref:`the Script Class system <doc_gdscript_basics_class_name>`. If you
are writing GDScript or NativeScript, we recommend using Script Classes instead.
To create a new node type, you can use the function

View File

@@ -1047,8 +1047,6 @@ There are 6 pattern types:
"Sword", "Splash potion", "Fist":
print("Yep, you've taken damage")
Classes
~~~~~~~
@@ -1065,6 +1063,11 @@ path. For example, if you name a script file ``character.gd``::
var Character = load("res://path/to/character.gd")
var character_node = Character.new()
.. _doc_gdscript_basics_class_name:
Registering named classes
~~~~~~~~~~~~~~~~~~~~~~~~~
Instead, you can give your class a name to register it as a new type in Godot's
editor. For that, you use the ``class_name`` keyword. You can add an
optional comma followed by a path to an image, to use it as an icon. Your class

View File

@@ -107,7 +107,7 @@ Currently you can use three types of… types:
1. :ref:`Built-in <doc_gdscript_builtin_types>`
2. Core classes and nodes (``Object``, ``Node``, ``Area2D``,
``Camera2D``, etc.)
3. Your own, custom classes. Look at the new :ref:`class_name <doc_scripting_continued_class_name>`
3. Your own, custom classes. Look at the new :ref:`class_name <doc_gdscript_basics_class_name>`
feature to register types in the editor.
.. note::