godotengine / godot-docs

Godot Engine official documentation
https://docs.godotengine.org
Other
3.81k stars 3.09k forks source link

Fix "for loop" error in GDScript reference #9535

Closed andrew-aaron closed 3 months ago

andrew-aaron commented 3 months ago

Your Godot version: Docs 4.2

Issue description: The section about for loops says:

for i in 2.2:
    statement # Similar to range(ceil(2.2)).

but this is incorrect as this will output "0, 1" in the Output console. It should be:

for i in 2.2:
    statement # Similar to range(floor(2.2)).

URL to the documentation page (if already existing): https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html

aGuyWhoMadeGames commented 3 months ago

It should actually be range(round(2.2)) as running:

for i in 2.6:
    print(i)

prints:

0
1
2
dalexeev commented 3 months ago

but this is incorrect as this will output "0, 1"

The right edge is excluded, see https://github.com/godotengine/godot-docs/pull/9539#pullrequestreview-2136731495.

aGuyWhoMadeGames commented 3 months ago

but this is incorrect as this will output "0, 1"

The documentation seems to be correct here. I'm not sure how this result was achieved.

andrew-aaron commented 3 months ago

Everyone here is correct. I didn't check myself thoroughly enough. I got confused as I used range(). I then checked the "in 2.2" example. ceil() pushes 2.2 to 3, therefore the last value will be 2. My bad everyone.