Add script class docs

This commit is contained in:
Will Nations
2018-08-15 13:39:54 -05:00
parent f873b6f34e
commit af7625768f
3 changed files with 50 additions and 3 deletions
@@ -59,6 +59,10 @@ here's a simple example of how GDScript looks.
extends BaseClass
# optional script class with optional icon
class_name MyClass, "res://path/to/optional/icon.svg"
# Member Variables
var a = 5
@@ -865,9 +869,13 @@ Classes
~~~~~~~
By default, the body of a script file is an unnamed class and it can
only be referenced externally as a resource or file. Class syntax is
meant to be compact and can only contain member variables or
functions. Static functions are allowed, but not static members (this is
only be referenced externally as a resource or file. Users can also define
an explicit name for a script using the 'class_name' keyword, optionally
followed by a path to an image resource. Named scripts appear in Godot
Engine's editor with their base class icon or the custom defined icon.
Class syntax is meant to be very compact and can only contain member variables
or functions. Static functions are allowed, but not static members (this is
in the spirit of thread safety, since scripts can be initialized in
separate threads without the user knowing). In the same way, member
variables (including arrays and dictionaries) are initialized every time
@@ -878,11 +886,18 @@ Below is an example of a class file.
::
# Saved as a file named 'myclass.gd'.
class_name MyClass
var a = 5
func print_value_of_a():
print(a)
func print_script_three_times():
print(get_script())
print(ResourceLoader.load("res://myclass.gd"))
print(MyClass)
Inheritance
^^^^^^^^^^^
@@ -381,3 +381,35 @@ The advantage of this two-step process is that a packed scene may be
kept loaded and ready to use so that you can create as many
instances as desired. This is especially useful to quickly instance
several enemies, bullets, and other entities in the active scene.
Script Classes
--------------
Godot has a "Script Class" feature to register individual scripts with the
Editor. By default, unnamed scripts are only accessible by loading the file
directly. Users name the script and give it an optional icon. These name-script
pairings are then supplied to scripting languages in Godot. The named scripts
that derive Node or Resource will show up in their respective creation dialogs
in the Editor.
At this time...
- Only GDScript and NativeScript (C++ and other GDNative-powered languages) can register scripts.
- Only GDScript creates global variables for each named script.
.. 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 # script
var cppNode = MyCppNode.new() # instance of a script
cppNode.queue_free()
.. image:: img/script_class_nativescript_example.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB