Skip to content

Array.resize() doesn't mention typed arrays #9005

Closed
godotengine/godot
#69451
@thiagola92

Description

@thiagola92

Your Godot version: v4.2.1.stable.official [b09f793f5]

Issue description:
It's silly to report this but this is incorrect when the array has type:

If the array size is smaller, elements are cleared, if bigger, new elements are null.

They receive the initialization value for their type.

var a = []
var b: Array = []
var c: Array[bool] = []
var d: Array[int] = []
var e: Array[float] = []
var f: Array[String] = []
var g: Array[Array] = []
var h: Array[Dictionary] = []

a.resize(1)
b.resize(1)
c.resize(1)
d.resize(1)
e.resize(1)
f.resize(1)
g.resize(1)
h.resize(1)

printt("a", a)
printt("b", b)
printt("c", c)
printt("d", d)
printt("e", e)
printt("f", f)
printt("g", g)
printt("h", h)

Result:

a	[<null>]
b	[<null>]
c	[false]
d	[0]
e	[0]
f	[""]
g	[[]]
h	[{  }]

URL to the documentation page:
https://docs.godotengine.org/en/latest/classes/class_array.html#class-array-method-resize

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:class referenceIssues and PRs about the class reference, which should be addressed on the Godot engine repositoryenhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions