Export var Control.GrowDirection how to add array of 2 values, Custom Resource

godot-4

Question

Is it possible to get two values in the same array - grow horizontal and grow vertical, something like this:
@export var _grow_direction : Array[Control.GrowDirection,Control.GrowDirection] = [Control.GROW_DIRECTION_BEGIN,Control.GROW_DIRECTION_BEGIN]

This works, but has only one value:
@export var _grow_direction : Array[Control.GrowDirection] = [Control.GROW_DIRECTION_BEGIN]

I would like to have one element containing both values for horizontal and vertical grow-value info. So its shows in the editor selectable pulldown menu with Grow Direction -info texts. Thanks!

Yes.

@export var _grow_direction : Array[Control.GrowDirection] = [Control.GROW_DIRECTION_BEGIN, Control.GROW_DIRECTION_BEGIN]

After the colon : is the type, Array[Control.GrowDirection] so this is an array that can store GrowDirections values. You can give it as many as you’d like. And as an export you can add to it in the editor too.

For a simpler example of this static typing let’s use ints

@export var numbers: Array[int] = [1, 1, 2, 2, 3, 4]

Array[int] is the type, after the equals sign is the value.

You can also omit the type entirely.

@export var _grow_direction = [Control.GROW_DIRECTION_BEGIN, Control.GROW_DIRECTION_BEGIN]
1 Like

Super! Thanks! (feeling pretty stupid now :smile:)

damn - this wasnt what I meant - I want nested array;
Array that contains Array with pre values; Grow Horizontal and grow vertical values)

I have used to made these with Vector2 etc. and take, in this case, x(=horizontal),y(=vertical)-value. But it would be so much cleaner to meke selection directly from the pulldown with correct values.

example like: @export var _content_anchor : Array[Vector4] = [Vector4(0.5,0.5,0.5,0.5)]

Just because I dont know is it possible to any other way to give one array element value of two or more values in one go. Is it possible only by doing custom resource just for this - havent seen that a good solution anyway.

In this case my export var is:
## x = Horizontal, y = Vertical, 0: END, 1: BOTH, 2: BEGIN
@export var _grow_direction : Array[Vector2] = [Vector2(0,0)]

I think nested arrays don’t have static typing yet, but you can make them with inner square brackets

@export var grow_direction: Array[Array] = [[1, 2], [1, 3], [2, 3]]

hmm, this somehow works:
@export var _content_grow_dir : Array = [[Control.GROW_DIRECTION_END,Control.GROW_DIRECTION_END]]

It gives nested array with values of [1,1]. I assume this is not possible without making custom resourse to make it so, that there is 2 pulldown menus with selectable text -values. I stick with Vector2, it works fine in this case anyway. Thanks!