class_packedstringarray.rst 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.2/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.2/doc/classes/PackedStringArray.xml.
  6. .. _class_PackedStringArray:
  7. PackedStringArray
  8. =================
  9. A packed array of :ref:`String<class_String>`\ s.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. An array specifically designed to hold :ref:`String<class_String>`\ s. Packs data tightly, so it saves memory for large array sizes.
  14. If you want to join the strings in the array, use :ref:`String.join<class_String_method_join>`.
  15. ::
  16. var string_array = PackedStringArray(["hello", "world"])
  17. var string = " ".join(string_array)
  18. print(string) # "hello world"
  19. .. note::
  20. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  21. .. rst-class:: classref-introduction-group
  22. Tutorials
  23. ---------
  24. - `OS Test Demo <https://godotengine.org/asset-library/asset/677>`__
  25. .. rst-class:: classref-reftable-group
  26. Constructors
  27. ------------
  28. .. table::
  29. :widths: auto
  30. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`PackedStringArray<class_PackedStringArray_constructor_PackedStringArray>` **(** **)** |
  32. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`PackedStringArray<class_PackedStringArray_constructor_PackedStringArray>` **(** :ref:`PackedStringArray<class_PackedStringArray>` from **)** |
  34. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`PackedStringArray<class_PackedStringArray_constructor_PackedStringArray>` **(** :ref:`Array<class_Array>` from **)** |
  36. +---------------------------------------------------+----------------------------------------------------------------------------------------------------------------------------------------------------+
  37. .. rst-class:: classref-reftable-group
  38. Methods
  39. -------
  40. .. table::
  41. :widths: auto
  42. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`bool<class_bool>` | :ref:`append<class_PackedStringArray_method_append>` **(** :ref:`String<class_String>` value **)** |
  44. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  45. | void | :ref:`append_array<class_PackedStringArray_method_append_array>` **(** :ref:`PackedStringArray<class_PackedStringArray>` array **)** |
  46. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`int<class_int>` | :ref:`bsearch<class_PackedStringArray_method_bsearch>` **(** :ref:`String<class_String>` value, :ref:`bool<class_bool>` before=true **)** |
  48. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`clear<class_PackedStringArray_method_clear>` **(** **)** |
  50. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`int<class_int>` | :ref:`count<class_PackedStringArray_method_count>` **(** :ref:`String<class_String>` value **)** |const| |
  52. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`duplicate<class_PackedStringArray_method_duplicate>` **(** **)** |
  54. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`fill<class_PackedStringArray_method_fill>` **(** :ref:`String<class_String>` value **)** |
  56. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  57. | :ref:`int<class_int>` | :ref:`find<class_PackedStringArray_method_find>` **(** :ref:`String<class_String>` value, :ref:`int<class_int>` from=0 **)** |const| |
  58. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`bool<class_bool>` | :ref:`has<class_PackedStringArray_method_has>` **(** :ref:`String<class_String>` value **)** |const| |
  60. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`insert<class_PackedStringArray_method_insert>` **(** :ref:`int<class_int>` at_index, :ref:`String<class_String>` value **)** |
  62. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`bool<class_bool>` | :ref:`is_empty<class_PackedStringArray_method_is_empty>` **(** **)** |const| |
  64. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`bool<class_bool>` | :ref:`push_back<class_PackedStringArray_method_push_back>` **(** :ref:`String<class_String>` value **)** |
  66. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  67. | void | :ref:`remove_at<class_PackedStringArray_method_remove_at>` **(** :ref:`int<class_int>` index **)** |
  68. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`int<class_int>` | :ref:`resize<class_PackedStringArray_method_resize>` **(** :ref:`int<class_int>` new_size **)** |
  70. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`reverse<class_PackedStringArray_method_reverse>` **(** **)** |
  72. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`int<class_int>` | :ref:`rfind<class_PackedStringArray_method_rfind>` **(** :ref:`String<class_String>` value, :ref:`int<class_int>` from=-1 **)** |const| |
  74. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set<class_PackedStringArray_method_set>` **(** :ref:`int<class_int>` index, :ref:`String<class_String>` value **)** |
  76. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`int<class_int>` | :ref:`size<class_PackedStringArray_method_size>` **(** **)** |const| |
  78. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`slice<class_PackedStringArray_method_slice>` **(** :ref:`int<class_int>` begin, :ref:`int<class_int>` end=2147483647 **)** |const| |
  80. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  81. | void | :ref:`sort<class_PackedStringArray_method_sort>` **(** **)** |
  82. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`PackedByteArray<class_PackedByteArray>` | :ref:`to_byte_array<class_PackedStringArray_method_to_byte_array>` **(** **)** |const| |
  84. +---------------------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------+
  85. .. rst-class:: classref-reftable-group
  86. Operators
  87. ---------
  88. .. table::
  89. :widths: auto
  90. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`bool<class_bool>` | :ref:`operator !=<class_PackedStringArray_operator_neq_PackedStringArray>` **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)** |
  92. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`PackedStringArray<class_PackedStringArray>` | :ref:`operator +<class_PackedStringArray_operator_sum_PackedStringArray>` **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)** |
  94. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :ref:`bool<class_bool>` | :ref:`operator ==<class_PackedStringArray_operator_eq_PackedStringArray>` **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)** |
  96. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :ref:`String<class_String>` | :ref:`operator []<class_PackedStringArray_operator_idx_int>` **(** :ref:`int<class_int>` index **)** |
  98. +---------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------+
  99. .. rst-class:: classref-section-separator
  100. ----
  101. .. rst-class:: classref-descriptions-group
  102. Constructor Descriptions
  103. ------------------------
  104. .. _class_PackedStringArray_constructor_PackedStringArray:
  105. .. rst-class:: classref-constructor
  106. :ref:`PackedStringArray<class_PackedStringArray>` **PackedStringArray** **(** **)**
  107. Constructs an empty **PackedStringArray**.
  108. .. rst-class:: classref-item-separator
  109. ----
  110. .. rst-class:: classref-constructor
  111. :ref:`PackedStringArray<class_PackedStringArray>` **PackedStringArray** **(** :ref:`PackedStringArray<class_PackedStringArray>` from **)**
  112. Constructs a **PackedStringArray** as a copy of the given **PackedStringArray**.
  113. .. rst-class:: classref-item-separator
  114. ----
  115. .. rst-class:: classref-constructor
  116. :ref:`PackedStringArray<class_PackedStringArray>` **PackedStringArray** **(** :ref:`Array<class_Array>` from **)**
  117. Constructs a new **PackedStringArray**. Optionally, you can pass in a generic :ref:`Array<class_Array>` that will be converted.
  118. .. rst-class:: classref-section-separator
  119. ----
  120. .. rst-class:: classref-descriptions-group
  121. Method Descriptions
  122. -------------------
  123. .. _class_PackedStringArray_method_append:
  124. .. rst-class:: classref-method
  125. :ref:`bool<class_bool>` **append** **(** :ref:`String<class_String>` value **)**
  126. Appends an element at the end of the array (alias of :ref:`push_back<class_PackedStringArray_method_push_back>`).
  127. .. rst-class:: classref-item-separator
  128. ----
  129. .. _class_PackedStringArray_method_append_array:
  130. .. rst-class:: classref-method
  131. void **append_array** **(** :ref:`PackedStringArray<class_PackedStringArray>` array **)**
  132. Appends a **PackedStringArray** at the end of this array.
  133. .. rst-class:: classref-item-separator
  134. ----
  135. .. _class_PackedStringArray_method_bsearch:
  136. .. rst-class:: classref-method
  137. :ref:`int<class_int>` **bsearch** **(** :ref:`String<class_String>` value, :ref:`bool<class_bool>` before=true **)**
  138. Finds the index of an existing value (or the insertion index that maintains sorting order, if the value is not yet present in the array) using binary search. Optionally, a ``before`` specifier can be passed. If ``false``, the returned index comes after all existing entries of the value in the array.
  139. \ **Note:** Calling :ref:`bsearch<class_PackedStringArray_method_bsearch>` on an unsorted array results in unexpected behavior.
  140. .. rst-class:: classref-item-separator
  141. ----
  142. .. _class_PackedStringArray_method_clear:
  143. .. rst-class:: classref-method
  144. void **clear** **(** **)**
  145. Clears the array. This is equivalent to using :ref:`resize<class_PackedStringArray_method_resize>` with a size of ``0``.
  146. .. rst-class:: classref-item-separator
  147. ----
  148. .. _class_PackedStringArray_method_count:
  149. .. rst-class:: classref-method
  150. :ref:`int<class_int>` **count** **(** :ref:`String<class_String>` value **)** |const|
  151. Returns the number of times an element is in the array.
  152. .. rst-class:: classref-item-separator
  153. ----
  154. .. _class_PackedStringArray_method_duplicate:
  155. .. rst-class:: classref-method
  156. :ref:`PackedStringArray<class_PackedStringArray>` **duplicate** **(** **)**
  157. Creates a copy of the array, and returns it.
  158. .. rst-class:: classref-item-separator
  159. ----
  160. .. _class_PackedStringArray_method_fill:
  161. .. rst-class:: classref-method
  162. void **fill** **(** :ref:`String<class_String>` value **)**
  163. Assigns the given value to all elements in the array. This can typically be used together with :ref:`resize<class_PackedStringArray_method_resize>` to create an array with a given size and initialized elements.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_PackedStringArray_method_find:
  167. .. rst-class:: classref-method
  168. :ref:`int<class_int>` **find** **(** :ref:`String<class_String>` value, :ref:`int<class_int>` from=0 **)** |const|
  169. Searches the array for a value and returns its index or ``-1`` if not found. Optionally, the initial search index can be passed.
  170. .. rst-class:: classref-item-separator
  171. ----
  172. .. _class_PackedStringArray_method_has:
  173. .. rst-class:: classref-method
  174. :ref:`bool<class_bool>` **has** **(** :ref:`String<class_String>` value **)** |const|
  175. Returns ``true`` if the array contains ``value``.
  176. .. rst-class:: classref-item-separator
  177. ----
  178. .. _class_PackedStringArray_method_insert:
  179. .. rst-class:: classref-method
  180. :ref:`int<class_int>` **insert** **(** :ref:`int<class_int>` at_index, :ref:`String<class_String>` value **)**
  181. Inserts a new element at a given position in the array. The position must be valid, or at the end of the array (``idx == size()``).
  182. .. rst-class:: classref-item-separator
  183. ----
  184. .. _class_PackedStringArray_method_is_empty:
  185. .. rst-class:: classref-method
  186. :ref:`bool<class_bool>` **is_empty** **(** **)** |const|
  187. Returns ``true`` if the array is empty.
  188. .. rst-class:: classref-item-separator
  189. ----
  190. .. _class_PackedStringArray_method_push_back:
  191. .. rst-class:: classref-method
  192. :ref:`bool<class_bool>` **push_back** **(** :ref:`String<class_String>` value **)**
  193. Appends a string element at end of the array.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. _class_PackedStringArray_method_remove_at:
  197. .. rst-class:: classref-method
  198. void **remove_at** **(** :ref:`int<class_int>` index **)**
  199. Removes an element from the array by index.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. _class_PackedStringArray_method_resize:
  203. .. rst-class:: classref-method
  204. :ref:`int<class_int>` **resize** **(** :ref:`int<class_int>` new_size **)**
  205. Sets the size of the array. If the array is grown, reserves elements at the end of the array. If the array is shrunk, truncates the array to the new size. Calling :ref:`resize<class_PackedStringArray_method_resize>` once and assigning the new values is faster than adding new elements one by one.
  206. .. rst-class:: classref-item-separator
  207. ----
  208. .. _class_PackedStringArray_method_reverse:
  209. .. rst-class:: classref-method
  210. void **reverse** **(** **)**
  211. Reverses the order of the elements in the array.
  212. .. rst-class:: classref-item-separator
  213. ----
  214. .. _class_PackedStringArray_method_rfind:
  215. .. rst-class:: classref-method
  216. :ref:`int<class_int>` **rfind** **(** :ref:`String<class_String>` value, :ref:`int<class_int>` from=-1 **)** |const|
  217. Searches the array in reverse order. Optionally, a start search index can be passed. If negative, the start index is considered relative to the end of the array.
  218. .. rst-class:: classref-item-separator
  219. ----
  220. .. _class_PackedStringArray_method_set:
  221. .. rst-class:: classref-method
  222. void **set** **(** :ref:`int<class_int>` index, :ref:`String<class_String>` value **)**
  223. Changes the :ref:`String<class_String>` at the given index.
  224. .. rst-class:: classref-item-separator
  225. ----
  226. .. _class_PackedStringArray_method_size:
  227. .. rst-class:: classref-method
  228. :ref:`int<class_int>` **size** **(** **)** |const|
  229. Returns the number of elements in the array.
  230. .. rst-class:: classref-item-separator
  231. ----
  232. .. _class_PackedStringArray_method_slice:
  233. .. rst-class:: classref-method
  234. :ref:`PackedStringArray<class_PackedStringArray>` **slice** **(** :ref:`int<class_int>` begin, :ref:`int<class_int>` end=2147483647 **)** |const|
  235. Returns the slice of the **PackedStringArray**, from ``begin`` (inclusive) to ``end`` (exclusive), as a new **PackedStringArray**.
  236. The absolute value of ``begin`` and ``end`` will be clamped to the array size, so the default value for ``end`` makes it slice to the size of the array by default (i.e. ``arr.slice(1)`` is a shorthand for ``arr.slice(1, arr.size())``).
  237. If either ``begin`` or ``end`` are negative, they will be relative to the end of the array (i.e. ``arr.slice(0, -2)`` is a shorthand for ``arr.slice(0, arr.size() - 2)``).
  238. .. rst-class:: classref-item-separator
  239. ----
  240. .. _class_PackedStringArray_method_sort:
  241. .. rst-class:: classref-method
  242. void **sort** **(** **)**
  243. Sorts the elements of the array in ascending order.
  244. .. rst-class:: classref-item-separator
  245. ----
  246. .. _class_PackedStringArray_method_to_byte_array:
  247. .. rst-class:: classref-method
  248. :ref:`PackedByteArray<class_PackedByteArray>` **to_byte_array** **(** **)** |const|
  249. Returns a :ref:`PackedByteArray<class_PackedByteArray>` with each string encoded as bytes.
  250. .. rst-class:: classref-section-separator
  251. ----
  252. .. rst-class:: classref-descriptions-group
  253. Operator Descriptions
  254. ---------------------
  255. .. _class_PackedStringArray_operator_neq_PackedStringArray:
  256. .. rst-class:: classref-operator
  257. :ref:`bool<class_bool>` **operator !=** **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)**
  258. Returns ``true`` if contents of the arrays differ.
  259. .. rst-class:: classref-item-separator
  260. ----
  261. .. _class_PackedStringArray_operator_sum_PackedStringArray:
  262. .. rst-class:: classref-operator
  263. :ref:`PackedStringArray<class_PackedStringArray>` **operator +** **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)**
  264. Returns a new **PackedStringArray** with contents of ``right`` added at the end of this array. For better performance, consider using :ref:`append_array<class_PackedStringArray_method_append_array>` instead.
  265. .. rst-class:: classref-item-separator
  266. ----
  267. .. _class_PackedStringArray_operator_eq_PackedStringArray:
  268. .. rst-class:: classref-operator
  269. :ref:`bool<class_bool>` **operator ==** **(** :ref:`PackedStringArray<class_PackedStringArray>` right **)**
  270. Returns ``true`` if contents of both arrays are the same, i.e. they have all equal :ref:`String<class_String>`\ s at the corresponding indices.
  271. .. rst-class:: classref-item-separator
  272. ----
  273. .. _class_PackedStringArray_operator_idx_int:
  274. .. rst-class:: classref-operator
  275. :ref:`String<class_String>` **operator []** **(** :ref:`int<class_int>` index **)**
  276. Returns the :ref:`String<class_String>` at index ``index``. Negative indices can be used to access the elements starting from the end. Using index out of array's bounds will result in an error.
  277. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  278. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  279. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  280. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  281. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  282. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  283. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`