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

No way to set a float prop to 0.0 in tiled extension #3423

Closed
fmoo opened this issue Jul 25, 2022 · 3 comments
Closed

No way to set a float prop to 0.0 in tiled extension #3423

fmoo opened this issue Jul 25, 2022 · 3 comments
Assignees
Labels
bug Broken behavior. missing feature It's not just a feature, it's a feature that really should be there!

Comments

@fmoo
Copy link
Contributor

fmoo commented Jul 25, 2022

Describe the bug
Tiled extensions are unable to set map, layer properties to a float value of 0.0.

To Reproduce
Steps to reproduce the behavior:

  1. use the following JS in a tiled extension:
tiled.assetOpened.connect((asset) => {
  if (asset.isTileMap) {
    asset.setProperty("autoscrollX", 1.0);
    asset.setProperty("autoscrollX", 0.0);
  }
});
  1. open a map.

Expected behavior
The map contains an "autoscrollX" property set to 0.0 (a float). Level designer can easily set the property to 0.1 or 0.3 without any additional steps.

Actual behavior
The map contains an "autoscrollX" property set to 0 (an integer). Level designer must right click and "convert to float" before they can use this property with decimal values.

Media
N/A

Specifications:

  • OS: Windows 11
  • Tiled Version: 1.9.0
@fmoo fmoo added the bug Broken behavior. label Jul 25, 2022
@eishiya
Copy link
Contributor

eishiya commented Jul 25, 2022

This isn't limited to 0.0, it happens to any whole number, including 1.0, 34987.0, etc.

This is a known issue mentioned in the API docs, it is a limitation of JavaScript, which does not distinguish ints and floats. Tiled guesses the property type based on the type of the value you give it, but integers and whole-number floats are ambiguous.

Possible solutions I mentioned when we discussed this issue on Discord:

  1. convertProperty(name, type) method that converts the current value to the desired type as well as it can. This is probably overkill, since this is only a problem with (a subset of) floats, and most conversions make no sense.
  2. Optional third parameter to setProperty(), something like a forceFloat bool which is used when the value is a number, and ignored otherwise.
  3. setFloatProperty(name, floatValue) method that works like setProperty, but the type is always float.

Option 2 is probably the cleanest one, from a script developer's perspective.

@bjorn bjorn added the missing feature It's not just a feature, it's a feature that really should be there! label Aug 12, 2022
@bjorn
Copy link
Member

bjorn commented Nov 4, 2022

I think I'll try adding setFloatProperty, since then we can naturally also have setColorProperty, since we have a similar problem with colors not being distinguishable from strings.

@bjorn bjorn self-assigned this Nov 4, 2022
@bjorn
Copy link
Member

bjorn commented Nov 4, 2022

I've pushed this change to a new 1.9 branch, since there was a localized string added on master so that would eventually become Tiled 1.10 now.

@bjorn bjorn closed this as completed in c5a0af7 Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Broken behavior. missing feature It's not just a feature, it's a feature that really should be there!
Projects
None yet
Development

No branches or pull requests

3 participants