summaryrefslogtreecommitdiff
path: root/modules/gdscript
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2022-02-18 00:48:33 +0100
committerMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2022-02-18 00:59:22 +0100
commitbac8e451c056173133d5f0f8c8706749e85bce35 (patch)
tree55292084f726c168d31a766f154cd65c24234809 /modules/gdscript
parent5b18a81be9736ad7f9824ea615dbe460a741b76c (diff)
Describe usage of float in range documentation
Diffstat (limited to 'modules/gdscript')
-rw-r--r--modules/gdscript/doc_classes/@GDScript.xml12
-rw-r--r--modules/gdscript/gdscript_analyzer.cpp2
2 files changed, 13 insertions, 1 deletions
diff --git a/modules/gdscript/doc_classes/@GDScript.xml b/modules/gdscript/doc_classes/@GDScript.xml
index 4d6320d8c3..d9fab01dce 100644
--- a/modules/gdscript/doc_classes/@GDScript.xml
+++ b/modules/gdscript/doc_classes/@GDScript.xml
@@ -186,6 +186,7 @@
<description>
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.
+ [code]range()(/code] converts all arguments to [int] before processing.
[codeblock]
print(range(4))
print(range(2, 5))
@@ -211,6 +212,17 @@
6
3
[/codeblock]
+ To iterate over [float], convert them in the loop.
+ [codeblock]
+ for i in range (3, 0, -1):
+ print(i / 10.0)
+ [/codeblock]
+ Output:
+ [codeblock]
+ 0.3
+ 0.2
+ 0.1
+ [/codeblock]
</description>
</method>
<method name="str" qualifiers="vararg">
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp
index 94daba4bf6..5bacfe1604 100644
--- a/modules/gdscript/gdscript_analyzer.cpp
+++ b/modules/gdscript/gdscript_analyzer.cpp
@@ -1241,7 +1241,7 @@ void GDScriptAnalyzer::resolve_for(GDScriptParser::ForNode *p_for) {
bool list_resolved = false;
// Optimize constant range() call to not allocate an array.
- // Use int, Vector2, Vector3 instead, which also can be used as range iterators.
+ // Use int, Vector2i, Vector3i instead, which also can be used as range iterators.
if (p_for->list && p_for->list->type == GDScriptParser::Node::CALL) {
GDScriptParser::CallNode *call = static_cast<GDScriptParser::CallNode *>(p_for->list);
GDScriptParser::Node::Type callee_type = call->get_callee_type();