class_array.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  2. .. DO NOT EDIT THIS FILE, but the doc/base/classes.xml source instead.
  3. .. _class_Array:
  4. Array
  5. =====
  6. **Category:** Built-In Types
  7. Brief Description
  8. -----------------
  9. Generic array datatype.
  10. Member Functions
  11. ----------------
  12. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  13. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`ColorArray<class_colorarray>` from **)** |
  14. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  15. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`Vector3Array<class_vector3array>` from **)** |
  16. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  17. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`Vector2Array<class_vector2array>` from **)** |
  18. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  19. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`StringArray<class_stringarray>` from **)** |
  20. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  21. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`RealArray<class_realarray>` from **)** |
  22. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  23. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`IntArray<class_intarray>` from **)** |
  24. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  25. | :ref:`Array<class_array>` | :ref:`Array<class_Array_Array>` **(** :ref:`RawArray<class_rawarray>` from **)** |
  26. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  27. | void | :ref:`append<class_Array_append>` **(** var value **)** |
  28. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  29. | void | :ref:`back<class_Array_back>` **(** **)** |
  30. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  31. | void | :ref:`clear<class_Array_clear>` **(** **)** |
  32. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`int<class_int>` | :ref:`count<class_Array_count>` **(** var value **)** |
  34. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`bool<class_bool>` | :ref:`empty<class_Array_empty>` **(** **)** |
  36. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  37. | void | :ref:`erase<class_Array_erase>` **(** var value **)** |
  38. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`int<class_int>` | :ref:`find<class_Array_find>` **(** var what, :ref:`int<class_int>` from=0 **)** |
  40. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`int<class_int>` | :ref:`find_last<class_Array_find_last>` **(** var value **)** |
  42. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  43. | void | :ref:`front<class_Array_front>` **(** **)** |
  44. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`bool<class_bool>` | :ref:`has<class_Array_has>` **(** var value **)** |
  46. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`int<class_int>` | :ref:`hash<class_Array_hash>` **(** **)** |
  48. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`insert<class_Array_insert>` **(** :ref:`int<class_int>` pos, var value **)** |
  50. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`invert<class_Array_invert>` **(** **)** |
  52. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`bool<class_bool>` | :ref:`is_shared<class_Array_is_shared>` **(** **)** |
  54. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`pop_back<class_Array_pop_back>` **(** **)** |
  56. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`pop_front<class_Array_pop_front>` **(** **)** |
  58. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`push_back<class_Array_push_back>` **(** var value **)** |
  60. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  61. | void | :ref:`push_front<class_Array_push_front>` **(** var value **)** |
  62. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  63. | void | :ref:`remove<class_Array_remove>` **(** :ref:`int<class_int>` pos **)** |
  64. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  65. | void | :ref:`resize<class_Array_resize>` **(** :ref:`int<class_int>` pos **)** |
  66. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`int<class_int>` | :ref:`rfind<class_Array_rfind>` **(** var what, :ref:`int<class_int>` from=-1 **)** |
  68. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`int<class_int>` | :ref:`size<class_Array_size>` **(** **)** |
  70. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`sort<class_Array_sort>` **(** **)** |
  72. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`sort_custom<class_Array_sort_custom>` **(** :ref:`Object<class_object>` obj, :ref:`String<class_string>` func **)** |
  74. +----------------------------+-----------------------------------------------------------------------------------------------------------------------------+
  75. Description
  76. -----------
  77. Generic array, contains several elements of any type, accessible by numerical index starting at 0. Negative indices can be used to count from the right, like in Python. Arrays are always passed by reference.
  78. Member Function Description
  79. ---------------------------
  80. .. _class_Array_Array:
  81. - :ref:`Array<class_array>` **Array** **(** :ref:`ColorArray<class_colorarray>` from **)**
  82. Construct an array from a :ref:`RawArray<class_rawarray>`.
  83. .. _class_Array_Array:
  84. - :ref:`Array<class_array>` **Array** **(** :ref:`Vector3Array<class_vector3array>` from **)**
  85. Construct an array from a :ref:`RawArray<class_rawarray>`.
  86. .. _class_Array_Array:
  87. - :ref:`Array<class_array>` **Array** **(** :ref:`Vector2Array<class_vector2array>` from **)**
  88. Construct an array from a :ref:`RawArray<class_rawarray>`.
  89. .. _class_Array_Array:
  90. - :ref:`Array<class_array>` **Array** **(** :ref:`StringArray<class_stringarray>` from **)**
  91. Construct an array from a :ref:`RawArray<class_rawarray>`.
  92. .. _class_Array_Array:
  93. - :ref:`Array<class_array>` **Array** **(** :ref:`RealArray<class_realarray>` from **)**
  94. Construct an array from a :ref:`RawArray<class_rawarray>`.
  95. .. _class_Array_Array:
  96. - :ref:`Array<class_array>` **Array** **(** :ref:`IntArray<class_intarray>` from **)**
  97. Construct an array from a :ref:`RawArray<class_rawarray>`.
  98. .. _class_Array_Array:
  99. - :ref:`Array<class_array>` **Array** **(** :ref:`RawArray<class_rawarray>` from **)**
  100. Construct an array from a :ref:`RawArray<class_rawarray>`.
  101. .. _class_Array_append:
  102. - void **append** **(** var value **)**
  103. Append an element at the end of the array (alias of :ref:`push_back<class_Array_push_back>`).
  104. .. _class_Array_back:
  105. - void **back** **(** **)**
  106. Returns the last element of the array if the array is not empty (size>0).
  107. .. _class_Array_clear:
  108. - void **clear** **(** **)**
  109. Clear the array (resize to 0).
  110. .. _class_Array_count:
  111. - :ref:`int<class_int>` **count** **(** var value **)**
  112. Return the amount of times an element is in the array.
  113. .. _class_Array_empty:
  114. - :ref:`bool<class_bool>` **empty** **(** **)**
  115. Return true if the array is empty (size==0).
  116. .. _class_Array_erase:
  117. - void **erase** **(** var value **)**
  118. Remove the first occurrence of a value from the array.
  119. .. _class_Array_find:
  120. - :ref:`int<class_int>` **find** **(** var what, :ref:`int<class_int>` from=0 **)**
  121. Searches the array for a value and returns its index or -1 if not found. Optionally, the initial search index can be passed.
  122. .. _class_Array_find_last:
  123. - :ref:`int<class_int>` **find_last** **(** var value **)**
  124. Searches the array in reverse order for a value and returns its index or -1 if not found.
  125. .. _class_Array_front:
  126. - void **front** **(** **)**
  127. Returns the first element of the array if the array is not empty (size>0).
  128. .. _class_Array_has:
  129. - :ref:`bool<class_bool>` **has** **(** var value **)**
  130. Return true if the array contains given value.
  131. ::
  132. [ "inside", 7 ].has("inside") == true
  133. [ "inside", 7 ].has("outside") == false
  134. [ "inside", 7 ].has(7) == true
  135. [ "inside", 7 ].has("7") == false
  136. .. _class_Array_hash:
  137. - :ref:`int<class_int>` **hash** **(** **)**
  138. Return a hashed integer value representing the array contents.
  139. .. _class_Array_insert:
  140. - void **insert** **(** :ref:`int<class_int>` pos, var value **)**
  141. Insert a new element at a given position in the array. The position must be valid, or at the end of the array (pos==size()).
  142. .. _class_Array_invert:
  143. - void **invert** **(** **)**
  144. Reverse the order of the elements in the array (so first element will now be the last).
  145. .. _class_Array_is_shared:
  146. - :ref:`bool<class_bool>` **is_shared** **(** **)**
  147. Get whether this is a shared array instance.
  148. .. _class_Array_pop_back:
  149. - void **pop_back** **(** **)**
  150. Remove the last element of the array.
  151. .. _class_Array_pop_front:
  152. - void **pop_front** **(** **)**
  153. Remove the first element of the array.
  154. .. _class_Array_push_back:
  155. - void **push_back** **(** var value **)**
  156. Append an element at the end of the array.
  157. .. _class_Array_push_front:
  158. - void **push_front** **(** var value **)**
  159. Add an element at the beginning of the array.
  160. .. _class_Array_remove:
  161. - void **remove** **(** :ref:`int<class_int>` pos **)**
  162. Remove an element from the array by index.
  163. .. _class_Array_resize:
  164. - void **resize** **(** :ref:`int<class_int>` pos **)**
  165. Resize the array to contain a different number of elements. If the array size is smaller, elements are cleared, if bigger, new elements are Null.
  166. .. _class_Array_rfind:
  167. - :ref:`int<class_int>` **rfind** **(** var what, :ref:`int<class_int>` from=-1 **)**
  168. 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.
  169. .. _class_Array_size:
  170. - :ref:`int<class_int>` **size** **(** **)**
  171. Return the amount of elements in the array.
  172. .. _class_Array_sort:
  173. - void **sort** **(** **)**
  174. Sort the array using natural order.
  175. .. _class_Array_sort_custom:
  176. - void **sort_custom** **(** :ref:`Object<class_object>` obj, :ref:`String<class_string>` func **)**
  177. Sort the array using a custom method. The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair of elements from the array) and must return true if the first argument is less than the second, and return false otherwise.