godotengine / godotengine/godot-docs

Request clarification or change on the use of the 'not' operator on strings.

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

Description

**Your Godot version:**

4.1.3 to 4.3

**Issue description:**

The "String (GDscript)" page (Description, Paragraph 3) incorrectly states that "The `not` operator cannot be used. Instead, `is_empty()` should be used to check for empty strings." when referring to boolean string comparison.

However, the code below works as expected and does not reflect the wording of the doc page.
`var my_str: String = ""`

`if my_str:`
` print("my_str evaluates to false and this will never be printed.")`
`if not my_str:`
` print("This evaluates to true as my_str does **not** evaluate to true.")`

I'm not certain of the original intention, but I believe the page should be changed to: "The `not` operator **should** not be used." leading the user to prefer using `is_empty()` to check instead.

The intention may also have been to state that the `not`operator cannot be used to **flip** or toggle the value, as in `my_bool = not my_bool`.

Though this might seem obvious, as just using `not` like this (`my_str = not my_str`) can't parse as strings have no inherent 'true' state to "flip" to, I think it still bears clarification.

**Additional info/Thoughts of a random Pedant:**

`my_str = "a very full string"`

Technically, `not my_str` could be the same as `""` but this can't work in reverse as there is an infinite number of strings that `not ""` could become, unlike a true/false toggle, which only has one option.

**URL to the documentation page:**

https://docs.godotengine.org/en/stable/classes/class_string.html

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.