summaryrefslogtreecommitdiff
path: root/modules/gdscript/doc_classes/@GDScript.xml
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-10-01 11:58:30 +0200
committerGitHub <noreply@github.com>2021-10-01 11:58:30 +0200
commit06c1b40b84645b4460dd49d95694a7779d636f92 (patch)
tree2481f310a705a24e7ab0695f7c2d1b02bb8bc994 /modules/gdscript/doc_classes/@GDScript.xml
parenta7011fa29488f5356949667eb8e2b296cbbd9923 (diff)
parent810d8f06b75cc1762776340aacc2ed6997d2c307 (diff)
Merge pull request #38397 from Calinou/doc-range-backwards-example
Diffstat (limited to 'modules/gdscript/doc_classes/@GDScript.xml')
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml17
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index 51b3452a3a..631ee4d895 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -176,7 +176,8 @@
<method name="range" qualifiers="vararg">
<return type="Array" />
<description>
- Returns an array with the given range. Range can be 1 argument N (0 to N-1), two arguments (initial, final-1) or three arguments (initial, final-1, increment).
+ Returns an array with the given range. Range can be 1 argument [code]N[/code] (0 to [code]N[/code] - 1), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). Returns an empty array if the range isn't valid (e.g. [code]range(2, 5, -1)[/code] or [code]range(5, 5, 1)[/code]).
+ Returns an array with the given range. [code]range()[/code] can have 1 argument N ([code]0[/code] to [code]N - 1[/code]), two arguments ([code]initial[/code], [code]final - 1[/code]) or three arguments ([code]initial[/code], [code]final - 1[/code], [code]increment[/code]). [code]increment[/code] can be negative. If [code]increment[/code] is negative, [code]final - 1[/code] will become [code]final + 1[/code]. Also, the initial value must be greater than the final value for the loop to run.
[codeblock]
print(range(4))
print(range(2, 5))
@@ -188,6 +189,20 @@
[2, 3, 4]
[0, 2, 4]
[/codeblock]
+ To iterate over an [Array] backwards, use:
+ [codeblock]
+ var array = [3, 6, 9]
+ var i := array.size() - 1
+ while i &gt;= 0:
+ print(array[i])
+ i -= 1
+ [/codeblock]
+ Output:
+ [codeblock]
+ 9
+ 6
+ 3
+ [/codeblock]
</description>
</method>
<method name="str" qualifiers="vararg">