How to set or define the default value of an exported variable at declaration?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Reginhowl
:warning: Old Version Published before Godot 3 was released.

Hello Godot Community,

I need help as i don’t know how to set the default value of an exported variable, without selecting on the inspectory by default, it returns a null or empty variable

Here is an example of how it is declared

export (bool) var isInteractable
export(String, "box", "circle", "triangle") var shape

which returns an empty result, unless you click in inspector, and not selecting the first choice as default

I have tried

export (bool) var isInteractable = true
export(String, "box", "circle", "triangle") var shape = "circle"

And it doesn’t seems to work
and declaring the value in func _ready(): seems not practical as it will override the value and inspector not updating real-time.

In short, what im trying to do is to set the default selected choice/parameter or get the first parameter

Sorry if i am confusing, This is my first time posting in godot and I am not an expert programmer, and i might have choose wrong terms. Thank you for your patience.

I did just quick test with export(bool) var bool_export = false # or true
and I got result what I expected.
if you changed default value after you made it once, there should be “restore” icon on right side on inspector.

volzhs | 2017-06-13 17:56

Yes, I don’t know why i did not notice or if i just got confused, but it does really work.
The restore icon really does help a lot

Reginhowl | 2017-06-14 19:56

:bust_in_silhouette: Reply From: eons

There is a behaviour that may change, if you modify an exported variable in code, the original value on the inspector remains the same and you have to reset it (reset/default button on the property) in the inspector to get the new one.

It seems when changing the default value on declaration, you must reselect the value in inspector, to refresh the “reset/default button”

I also tried declaring a new variable to test if it will select the default, and it did.
And lastly, tried selecting a different parameter in the inspector from default,
saved, close the scene and project, reload, and it is saved, and the value is also correct.

I feel like i might have just been confuse, or i may have just encountered an issue, I’ll update this when i encounter something.

Thanks!

Code used for setting the default variable:

export(String, "box", "circle", "triangle") var shape = "circle"

Reginhowl | 2017-06-14 19:57