Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading