generating docstrings - DouglasWebster/gdscript-to-restructured GitHub Wiki
Writing your code reference docstrings
Docstring or doc-comments in GDScript don't have any special markup.
In order for a script file to be documented it must have the class_name
defined. Any comment appearing at the beginning of the script file will be used as a general description for the class.
For example:
# The following class is the base class for all the characters in the game.
#
# The class defines the minimum attributes that are common to all characters
# and all the other types of characters should be inherited from this base class.
class_name CharacterBaseClass
extends KinematicBody2D
.
.
.
Using gdscript2rest commented lines are concatenated together, creating one long text comment, unless they are separated by and empty comment line which has the effect of starting a new paragraph.
As a comment surrounded by empty comment lines is a new line it is possible to use reStructuredText directives. For example:
# The following class is the base class for all the characters in the game.
#
#.. warning:: Creating a character from this base class will result in an unusable character
# as there are no movement actions defined in the base.
#
# The class defines the minimum attributes that are common to all characters
# and all the other types of characters should be inherited from this base class.
class_name CharacterBaseClass
extends KinematicBody2D
.
.
.
The .. warning:: directive will be passed through to the final .rst file as a separate section in the description and formatted appropriately.
The above applies to any commented blocks in the script file.
You can document classes, properties, and functions with comment blocks placed on the line before their definition provided,
- There are no uncommented lines - an empty comment line is permitted.
- The final comment line must immediately proceed the statement being commented.
# The following class is the base class for all the characters in the game.
#
#.. warning:: Creating a character from this base class will result in an unusable character
# as there are no movement actions defined in the base.
#
# The class defines the minimum attributes that are common to all characters
# and all the other types of characters should be inherited from this base class.
class_name CharacterBaseClass
extends KinematicBody2D
# A character can be in one of three states - it is fantasy after all!
enum CHARACTER-STATE {
ALIVE,
DEAD,
LIMBO
}
# Normally health will not go above 100% but certain potions and spells could override this
# The override is not allowed to go too high though
const MAX_HEALTH := 150.0
# The characters actuall health normally starts at 100%
var health := 100.0
# Let anyone who is interested know when this character changes state
signal state_changed
# This comment is purely internal as the gdscript2rest ignores all inbuilt
# virtual callback functions.
func _ready():
return ready():
# but all non virtual functions are listed out.
func ready():
return "All set, let's begin."
# The function documentation will list all parameters with their respective types if known
# It will also list the return type as well if there is one.
func am_i_stronger(opponents_strengh: float) -> bool:
# An internal comment is not documented - function internals SHOULD remain private!
# Later on I might change how I determine if the character is stronger or not
# and I don't want to have to redo all the API
return opponents_strength < my_strength
# And this comment doesn't get reported either
# but the function will, just without an expanation!
func do_nothing() -> void:
pass