Skip to content

Commit

Permalink
Fix method bind instructions and style
Browse files Browse the repository at this point in the history
  • Loading branch information
AThousandShips committed Jan 11, 2024
1 parent c20de5f commit bd81e44
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions contributing/development/core_and_modules/object_class.rst
Original file line number Diff line number Diff line change
@@ -71,13 +71,17 @@ Registering functions is one:

.. code-block:: cpp
ClassDB::bind_method(D_METHOD("methodname", "arg1name", "arg2name"), &MyCustomMethod);
ClassDB::bind_method(D_METHOD("methodname", "arg1name", "arg2name", "arg3name"), &MyCustomType::method);
Default values for arguments can be passed in reverse order:
Default values for arguments can be passed as parameters at the end:

.. code-block:: cpp
ClassDB::bind_method(D_METHOD("methodname", "arg1name", "arg2name"), &MyCustomType::method, DEFVAL(-1)); // default value for arg2name
ClassDB::bind_method(D_METHOD("methodname", "arg1name", "arg2name", "arg3name"), &MyCustomType::method, DEFVAL(-1), DEFVAL(-2)); // Default values for arg2name (-1) and arg3name (-2).
Default values must be provided in the same order as they are declared,
skipping requried arguments and then providing default values for the optional ones.
This matches the procedure in C++.

``D_METHOD`` is a macro that converts "methodname" to a StringName for more
efficiency. Argument names are used for introspection, but when
@@ -142,7 +146,7 @@ For example:
PropertyInfo(Variant::INT, "amount", PROPERTY_HINT_RANGE, "0,49,1", PROPERTY_USAGE_EDITOR)
This is an integer property named "amount". The hint is a range, and the range
This is an integer property named "amount". The hint is a range, and the range
goes from 0 to 49 in steps of 1 (integers). It is only usable for the editor
(editing the value visually) but won't be serialized.

0 comments on commit bd81e44

Please sign in to comment.