Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified StringName literal for single word text #8079

Closed
tokengamedev opened this issue Oct 12, 2023 · 5 comments
Closed

Simplified StringName literal for single word text #8079

tokengamedev opened this issue Oct 12, 2023 · 5 comments

Comments

@tokengamedev
Copy link

Describe the project you are working on

Casual Game in 4.2

Describe the problem or limitation you are having in your project

Currently the StringName literals are identified as &"hello godot". It is well and fine.
For single word text, can it not be simplified by removing the quotes similar to Node Path like &hello_godot

Describe the feature / enhancement and how it helps to overcome the problem or limitation

It will help in reducing unnecessary quotes as in NodePath

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Support both the structure for String Name as given below

var str_name := &"Hello"

# Currently the below error outs as 'Expected expression for variable initial value after "=".'
var str_name := &Hello

If this enhancement will not be used often, can it be worked around with a few lines of script?

It will be used mostly as constants and keys to dictionary, where the text is not changing.

Is there a reason why this should be core and not an add-on in the asset library?

GDscript parser is part of core.

@dalexeev
Copy link
Member

I had a similar idea, but after some thought I concluded that this syntax might confuse users that there are pointers/references in GDScript:

node_2d.set(&global_scale, Vector2(8, 2.5))
tween.tween_property($Sprite, ^position, Vector2(100, 200), 1)

The quotes more clearly indicate that these are just strings:

node_2d.set(&"global_scale", Vector2(8, 2.5))
tween.tween_property($Sprite, ^"position", Vector2(100, 200), 1)

@Mickeon
Copy link

Mickeon commented Oct 12, 2023

Yeah. It first sounds good on paper but by all practical means, StringNames are Strings and a vast majority of users wouldn't want to even realise there's a distinction between the two, let alone seeing a somewhat "magical" symbol behind what is just one character away from referring to the value of a property.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 12, 2023

Duplicate of #4721 ;)

It will be used mostly as constants and keys to dictionary, where the text is not changing.

Note that currently Dictionaries will implicitly convert StringNames to Strings, making them actually slower: godotengine/godot#68834
There is a pending PR that fixes it, but it's still not merged.

@KoBeWi KoBeWi closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2023
@tokengamedev
Copy link
Author

tokengamedev commented Oct 12, 2023

I am ok with it being not happening and getting closed, as people coming from C++ background will mistake as a referenced variable rather than StringName (not String), which is actually it is.
StringName is not a String, rather it is pointer to a string (correct me if I am wrong).
It is hard to distinguish between two, I will delve into the StringName code sometime, to understand better.

From #4721 I only got, that it was closed because nobody wants to add more colors, although few people liked the proposal. This is disappointing.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 12, 2023

#4721 is not closed and the colors were actually implemented. The syntax is still being discussed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants