mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Improve documentation related to Pool*Array value passing caveats
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user