godotengine / godotengine/godot-docs

Misleading example about casting String as int.

Open
#6,948 1 comment 0 reactions 0 assignees View on GitHub
area:manual bug
Dominant language
reStructuredText
Stars
5.7k
Forks
3.8k
Avg merge
1d 20h
Merged PRs (30d)
25

Description

**Your Godot version:**
4.0.stable

**Issue description:**
Casting.

It seems that this part in the docs is wrong:

```gdscript
# For built-in types, they will be forcibly converted if possible, otherwise the engine will raise an error.

var my_int: int
my_int = "123" as int # The string can be converted to int.
```

If you try to do this right now in Godot 4.0.stable, you will get an Error.

```Cannot cast a value of type "String" as "int"```

**URL to the documentation page:**
https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#casting

If you know how to fix the issue you are reporting please
consider opening a pull request. We provide a tutorial on
using git here: https://docs.godotengine.org/en/stable/community/contributing/pr_workflow.html,
writing documentation at https://docs.godotengine.org/en/stable/community/contributing/docs_writing_guidelines.html
and contributing to the class reference here: https://docs.godotengine.org/en/stable/community/contributing/updating_the_class_reference.html

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.