Search code examples
godotgdscriptgodot4

Quick question about Godot 4 exporting a set variable


I am just starting out Godot and I need a little help with some platforming code written in Godot 4

How do I set a default value to this -> @export var speed:int: set = set_speed

The language being used in the code is gdscript


Solution

  • Generally, we write the setters and getters on a separate line

    @export var speed: int:
        set = set_speed
    

    And now this looks like an ordinary variable declaration, followed by some modifiers. We can put the initial value exactly where we would for a variable that didn't have custom accessors: after the type.

    @export var speed: int = 0:
        set = set_speed