FunkinCrew / Funkin

A rhythm game made with HaxeFlixel
https://www.newgrounds.com/portal/view/770371
Other
2.98k stars 2.3k forks source link

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

Open Starexify opened 3 days ago

Starexify commented 3 days ago

Issue Checklist

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