Skip to content

Commit

Permalink
Fix _set example
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Aug 12, 2023
1 parent 4714e95 commit 90160ef
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions doc/classes/Object.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
[codeblocks]
[gdscript]
func _get(property):
if (property == "fake_property"):
if property == "fake_property":
print("Getting my property!")
return 4

Expand Down Expand Up @@ -212,21 +212,28 @@
Combined with [method _get] and [method _get_property_list], this method allows defining custom properties, which is particularly useful for editor plugins. Note that a property [i]must[/i] be present in [method get_property_list], otherwise this method will not be called.
[codeblocks]
[gdscript]
var internal_data = {}

func _set(property, value):
if (property == "fake_property"):
print("Setting my property to ", value)
if property == "fake_property":
# Storing the value in the fake property.
internal_data["fake_property"] = value
return true

func _get_property_list():
return [
{ "name": "fake_property", "type": TYPE_INT }
]
[/gdscript]
[csharp]
private Godot.Collections.Dictionary _internalData = new Godot.Collections.Dictionary();

public override void _Set(StringName property, Variant value)
{
if (property == "FakeProperty")
{
GD.Print($"Setting my property to {value}");
// Storing the value in the fake property.
_internalData["FakeProperty"] = value;
return true;
}

Expand Down

0 comments on commit 90160ef

Please sign in to comment.