From 5a215637078b3a06960c826084482798017c710b Mon Sep 17 00:00:00 2001 From: Nathan Lovato Date: Sat, 7 Nov 2020 23:23:19 -0600 Subject: [PATCH] Merge class_name docs from scripting_continued.rst into gdscript docs --- getting_started/step_by_step/resources.rst | 2 +- .../step_by_step/scripting_continued.rst | 46 +------------------ .../autoloads_versus_internal_nodes.rst | 2 +- .../best_practices/scenes_versus_scripts.rst | 2 +- tutorials/plugins/editor/making_plugins.rst | 2 +- .../scripting/gdscript/gdscript_basics.rst | 7 ++- .../scripting/gdscript/static_typing.rst | 2 +- 7 files changed, 12 insertions(+), 51 deletions(-) diff --git a/getting_started/step_by_step/resources.rst b/getting_started/step_by_step/resources.rst index c5448d504..716440589 100644 --- a/getting_started/step_by_step/resources.rst +++ b/getting_started/step_by_step/resources.rst @@ -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 `, +If the script's language supports :ref:`script classes `, 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. diff --git a/getting_started/step_by_step/scripting_continued.rst b/getting_started/step_by_step/scripting_continued.rst index 48589c326..4441c81c1 100644 --- a/getting_started/step_by_step/scripting_continued.rst +++ b/getting_started/step_by_step/scripting_continued.rst @@ -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() ` -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. diff --git a/tutorials/best_practices/autoloads_versus_internal_nodes.rst b/tutorials/best_practices/autoloads_versus_internal_nodes.rst index 14055d3e7..5c4b56e5a 100644 --- a/tutorials/best_practices/autoloads_versus_internal_nodes.rst +++ b/tutorials/best_practices/autoloads_versus_internal_nodes.rst @@ -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 -` keyword in GDScript. +` keyword in GDScript. When it comes to data, you can either: diff --git a/tutorials/best_practices/scenes_versus_scripts.rst b/tutorials/best_practices/scenes_versus_scripts.rst index 8437c1af7..c3ac2af9d 100644 --- a/tutorials/best_practices/scenes_versus_scripts.rst +++ b/tutorials/best_practices/scenes_versus_scripts.rst @@ -112,7 +112,7 @@ There are two systems for registering types... - Set up using :ref:`EditorPlugin.add_custom_type `. -- :ref:`Script Classes ` +- :ref:`Script Classes ` - Editor and runtime accessible. diff --git a/tutorials/plugins/editor/making_plugins.rst b/tutorials/plugins/editor/making_plugins.rst index f6492a75f..c002b12e6 100644 --- a/tutorials/plugins/editor/making_plugins.rst +++ b/tutorials/plugins/editor/making_plugins.rst @@ -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 `. If you + :ref:`the Script Class system `. If you are writing GDScript or NativeScript, we recommend using Script Classes instead. To create a new node type, you can use the function diff --git a/tutorials/scripting/gdscript/gdscript_basics.rst b/tutorials/scripting/gdscript/gdscript_basics.rst index 76eb40bbc..ce9f1b5ff 100644 --- a/tutorials/scripting/gdscript/gdscript_basics.rst +++ b/tutorials/scripting/gdscript/gdscript_basics.rst @@ -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 diff --git a/tutorials/scripting/gdscript/static_typing.rst b/tutorials/scripting/gdscript/static_typing.rst index f24010e76..217d8a3e4 100644 --- a/tutorials/scripting/gdscript/static_typing.rst +++ b/tutorials/scripting/gdscript/static_typing.rst @@ -107,7 +107,7 @@ Currently you can use three types of… types: 1. :ref:`Built-in ` 2. Core classes and nodes (``Object``, ``Node``, ``Area2D``, ``Camera2D``, etc.) -3. Your own, custom classes. Look at the new :ref:`class_name ` +3. Your own, custom classes. Look at the new :ref:`class_name ` feature to register types in the editor. .. note::