Improve documentation related to Pool*Array value passing caveats

This commit is contained in:
Hugo Locurcio
2022-03-28 16:16:41 +02:00
parent 288370609c
commit b47466bc59
7 changed files with 102 additions and 11 deletions

View File

@@ -1,11 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="PoolStringArray" version="3.5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A pooled array of [String].
A pooled array of [String]s.
</brief_description>
<description>
An array specifically designed to hold [String]s. Optimized for memory usage, does not fragment the memory.
[b]Note:[/b] This type is passed by value and not by reference.
[b]Note:[/b] This type is passed by value and not by reference. This means that when [i]mutating[/i] a class property of type [PoolStringArray] or mutating a [PoolStringArray] within an [Array] or [Dictionary], changes will be lost:
[codeblock]
var array = [PoolStringArray()]
array[0].push_back("hello")
print(array) # [[]] (empty PoolStringArray within an empty Array)
[/codeblock]
Instead, the entire [PoolStringArray] property must be [i]reassigned[/i] with [code]=[/code] for it to be changed:
[codeblock]
var array = [PoolStringArray()]
var pool_array = array[0]
pool_array.push_back("hello")
array[0] = pool_array
print(array) # [[hello]] (PoolStringArray with 1 element inside an Array)
[/codeblock]
</description>
<tutorials>
<link title="OS Test Demo">https://godotengine.org/asset-library/asset/677</link>