Skip to content

Conversation

@aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Dec 14, 2024

This is a general usability improvement for people using the Expression class with user-supplied input, such as the Godot editor inspector. This way, users will not have to capitalize things like pi/2, it will just work. Without this change, users would have to write PI/2, PI / 2, or similar.

This won't break user code unless they were using pi, tau, inf, or nan as variable names, but I doubt that.

EDIT: Updated the PR to support any casing. pi, PI, Pi, pI, true, True, TRUE, etc.

Copy link
Contributor

@kiroxas kiroxas Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if (id.nocasecmp_to("pi") == 0) ? Would allow Pi, TaU or iNf as well, not sure if it's desired.

Copy link
Member Author

@aaronfranke aaronfranke Dec 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! Actually, I think an even better option would be to support this for all constants / operators, so Python users will feel at home writing True and such, SQL users will feel at home writing AND/OR/NOT, C# users can write Tau etc, and users won't have to remember the capitalization.

@aaronfranke aaronfranke changed the title Allow using lowercase constants in Expression Allow using any-case constants in Expression Dec 14, 2024
@aaronfranke aaronfranke force-pushed the expression-lowercase branch from 9fe6c82 to 6019cfb Compare January 3, 2025 18:17
@akien-mga
Copy link
Member

I don't really see why Expression should be special cased like this. Its parser is meant to be as close to GDScript as possible, so allowing expressions which aren't supported in GDScript seems weird to me.

@aaronfranke
Copy link
Member Author

Is that a stated goal of Expression? The docs don't explicitly mention that: https://docs.godotengine.org/en/stable/classes/class_expression.html

Expression is used by the Godot editor for user input in Range, in which case inf and -inf and so on should be allowed. Another option would be to fix it only in Range, which would add a step of searching for and replacing several substrings, such as replacing "inf" with "INF" before giving the value to Expression.

@Calinou
Copy link
Member

Calinou commented Apr 12, 2025

This is likely best implemented at a local level in Range/SpinBox/EditorSpinSlider, as per Prefer local solutions.

I also agree with Akien that Expression should remain as close as possible to GDScript's behavior for ease of learning (and porting code from one to the other).

@aaronfranke
Copy link
Member Author

True, it would be simple for SpinBox and EditorSpinSlider to capitalize the input text before parsing it with Expression.

@aaronfranke
Copy link
Member Author

aaronfranke commented Jul 4, 2025

Re-opening because PR #105330 is infeasible and the problem still needs to be solved.

@aaronfranke aaronfranke reopened this Jul 4, 2025
@aaronfranke aaronfranke force-pushed the expression-lowercase branch from 801fb4f to eb23ced Compare July 4, 2025 00:07
@Chaosus Chaosus added this to the 4.6 milestone Jul 4, 2025
@aaronfranke aaronfranke force-pushed the expression-lowercase branch from eb23ced to 3065ea1 Compare August 20, 2025 21:49
@aaronfranke aaronfranke modified the milestones: 4.6, 4.7 Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants