mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-04 14:11:02 +03:00
Update gdscript_styleguide.rst (#6379)
Adds two changes: - makes it clear where subclasses should go (at the bottom of the script) - put the `_enter_tree()` method before `_ready()` but after `_init()` since that's the order in which the methods are executed
This commit is contained in:
@@ -44,7 +44,11 @@ Here is a complete class example based on these guidelines:
|
||||
|
||||
func _init():
|
||||
add_to_group("state_machine")
|
||||
|
||||
|
||||
|
||||
func _enter_tree():
|
||||
print("this happens before the ready method!")
|
||||
|
||||
|
||||
func _ready():
|
||||
connect("state_changed", self, "_on_state_changed")
|
||||
@@ -88,6 +92,13 @@ Here is a complete class example based on these guidelines:
|
||||
print("state changed")
|
||||
state_changed.emit()
|
||||
|
||||
|
||||
class State:
|
||||
var foo = 0
|
||||
|
||||
func _init():
|
||||
print("Hello!")
|
||||
|
||||
.. _formatting:
|
||||
|
||||
Formatting
|
||||
@@ -703,10 +714,12 @@ We suggest to organize GDScript code this way:
|
||||
11. onready variables
|
||||
|
||||
12. optional built-in virtual _init method
|
||||
13. built-in virtual _ready method
|
||||
14. remaining built-in virtual methods
|
||||
15. public methods
|
||||
16. private methods
|
||||
13. optional built-in virtual _enter_tree() method
|
||||
14. built-in virtual _ready method
|
||||
15. remaining built-in virtual methods
|
||||
16. public methods
|
||||
17. private methods
|
||||
18. subclasses
|
||||
|
||||
We optimized the order to make it easy to read the code from top to bottom, to
|
||||
help developers reading the code for the first time understand how it works, and
|
||||
|
||||
Reference in New Issue
Block a user