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

Bug Report: createPrefItemNumber using a Float is complicated and buggy #3888

Open
2 tasks done
Starexify opened this issue Nov 22, 2024 · 0 comments
Open
2 tasks done
Labels
status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue.

Comments

@Starexify
Copy link

Issue Checklist

  • I have properly named my issue
  • I have checked the Issues/Discussions pages to see if my issue has already been reported

Platform

Itch.io (Downloadable Build) - Windows

Browser

None

Version

0.5.2

Description (include any images, videos, errors, or crash logs)

I try to make an custom Preference Option with Float instead of Int, and when I tried to go from 0.3 or higher down to 0, it returns an odd number.

This is my code:

preferences.createPrefItemNumber("HUD Opacity", "Changes the opacity of the HUD", function (value:Float) {
save.data.hudOpacity = value; },
function (value:Float):String {
Std.parseFloat(save.data.hudOpacity); }, save.data.hudOpacity, 0.0, 1.0, 0.1, 1);

And this is the method that I use that is from the base game:

/**
* Creates a pref item that works with general numbers
* @param onChange Gets called every time the player changes the value; use this to apply the value
* @param valueFormatter Will get called every time the game needs to display the float value; use this to change how the displayed value looks
* @param defaultValue The value that is loaded in when the pref item is created (usually your Preferences.settingVariable)
* @param min Minimum value (example: 0)
* @param max Maximum value (example: 10)
* @param step The value to increment/decrement by (default = 0.1)
* @param precision Rounds decimals up to a `precision` amount of digits (ex: 4 -> 0.1234, 2 -> 0.12)
*/
  function createPrefItemNumber(prefName:String, prefDesc:String, onChange:Float->Void, ?valueFormatter:Float->String, defaultValue:Int, min:Int, max:Int,
      step:Float = 0.1, precision:Int):Void
  {
    var item = new NumberPreferenceItem(0, (120 * items.length) + 30, prefName, defaultValue, min, max, step, precision, onChange, valueFormatter);
    items.addItem(prefName, item);
    preferenceItems.add(item.lefthandText);
  }

image
As you see in the image it shows basically 2.777777e^-17 etc, even tho the precision is set to 1 decimal after .

Also extra question, is there any way to set a float instead of int for the value and also save it even if you refresh the game and work properly?

Thanks for your help

Steps to Reproduce

  1. Try to create a createPrefItemNumber with Floats
  2. Shows a very low number but not 0
@Starexify Starexify added status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue. labels Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: pending triage The bug or PR has not been reviewed yet. type: minor bug Involves a minor bug or issue.
Projects
None yet
Development

No branches or pull requests

1 participant