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

Use float division by default in the inspector #6281

Closed
lunkums opened this issue Feb 13, 2023 · 4 comments
Closed

Use float division by default in the inspector #6281

lunkums opened this issue Feb 13, 2023 · 4 comments

Comments

@lunkums
Copy link

lunkums commented Feb 13, 2023

Describe the project you are working on

A 2D top down hack and slash game

Describe the problem or limitation you are having in your project

Finding the right value for export variables can be tedious when using division (i.e. input 1 / 3 expecting 0.333, but getting 0 instead and having to type in 1.0 / 3 to get the expected value).

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

Use float division by default in the inspector to find fractional values quickly.

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

When the user selects a value field in the inspector (i.e. an export value field from a script), and types 1 / 3 then hits enter, the expression should be parsed as a float division and return the value 0.333.

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

This could be a toggle option in Godot's editor settings (type: bool | path: interface/editor/float_division_in_field_expressions | display: Use float division in field expressions).

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

This is about improving the editor usability out of the box.

@Calinou
Copy link
Member

Calinou commented Feb 13, 2023

The inspector uses the Expression class, which performs integer division if given two integers for consisency with GDScript. Changing division to perform floating-point division in this case was rejected in the past, so this will require special-casing the editor inspector to turn integers into floats if an expression is detected.

@lunkums lunkums closed this as completed Feb 14, 2023
@lunkums
Copy link
Author

lunkums commented Feb 14, 2023

Closing this proposal because the default behavior is consistent with GDScript.

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2023
@AlfishSoftware
Copy link

AlfishSoftware commented Jul 6, 2023

That's terrible behavior, though. The inspector is not a programming language and a field in the inspector is not a coding area - if anything, people will see it like a calculator.
This is an important necessary feature that should work predictably; it shouldn't be replaced with irregular behavior just because of some technicality. This badly hurts usability, even for coders and will confuse beginners.

Often you want to quickly divide a bunch of values to make adjustments in a batch, without having to pay attention to the actual value. If the field is float, then adding /4 at the end of the current value should give me a float division always. Current behavior is awful because this will depend on the current value. If it shows 1.01 then I get it right, but if it happens to show 1 instead, then I won't get 1.0/4 = 0.25, but an integer division nobody would expect on a float field.

The parser that evaluates this should either:

  • parse all numeric literals as the field type - if the field is long, then it's only fair that it would make integer division
  • parse all numeric literals as double, like in JS, then cast the calculation result to the field type at the end
  • or just cast values to double before all divisions

If you really want to allow integer/floor division in float fields, then make the inspector fields accept a // operator like in Python, or a div function.

Or, if you really won't change this, at least make it so float fields that display as integer like 1 become 1.0 once you click to edit them. Not the ideal, but sorta solves the problem at least.

@Calinou Please consider reopening.

@Calinou
Copy link
Member

Calinou commented Jul 6, 2023

Or, if you really won't change this, at least make it so float fields that display as integer like 1 become 1.0 once you click to edit them. Not the ideal, but sorta solves the problem at least.

See godotengine/godot#45303 which implements this.

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