Jump to content

[LE] MCM slider's formatString: How do i put a float literal value?


Recommended Posts

First of all, i don't know if it's the correct place to ask because there don't seem to be a thread specifically for MCM scripting, so i apologize in advance if it's indeed not the correct place. But if you ask me to ask in the MCM page (the github?), i'd say that i'm not familiar with that site so i prefer to ask in a place where i'm more familiar with. Now, to the issue i'm having...

 

I'm still new to MCM scripting although i've managed to tweak several MCM config scripts which seemed to work in game. But currently, i'm stumbled into an issue, which is to properly show the float literal value for some sliders. To be exact, in a case, i'm trying to put a slider about level mult, which has the range of 0 to 5 with the interval of 0.05. At first, i wrote the formatString by "{0} X" (ie. n X level mult), but it couldn't show the float value and instead only as integer values (ie. 1X, 2X, 3X, 4X, and 5X). Then i tried to write the formatString by "{0.0} X", and it still didn't work. What i want is for the formatString to show, for example, "1.25 X" if i put the slider into that number, and et cetera. So, how do i write it correctly?

Link to comment
Share on other sites

Are you changing it in both the AddSliderOption and SetSliderOption (or their state versions if you the state method)?

 

Both might need to be identical in order to work properly. Cannot say for sure as the only sliders I have set up used a step interval of 1.0 and I had no need to change the default value of the FormatString parameter.

Link to comment
Share on other sites

link you mentioned: https://github.com/schlangster/skyui/wiki/MCM-Option-Types
Slider Option
**************
Unlike the previous option types, slider options are dialog-based.
This means selecting the option won't immediately result in a selection event,
but instead a dialog is opened and a "OnOptionSliderOpen()" event is generated.

In "OnOptionSliderOpen()" you have to set up the parameters for the dialog.

Once the user has accepted a new value, "OnOptionSliderAccept()" is executed.
The dialog may also be canceled, in which case no further event is generated.

With the format string parameter you can embed the slider value in a string, e.g.
"Every {0} hours", where {0} is replaced by the current value.

The number inside the brackets sets the decimal places:
A value of 1 with format string {2} is displayed as 1.00.

A value of 2 with format string {1} is displayed as 2.0.

-- Functions: --

; Add
int function AddSliderOption(string text, float value, string formatString = "{0}")

; Change
function SetSliderOptionValue(int option, float value, string formatString = "{0}")
; Dialog setup
function SetSliderDialogStartValue(float value)
function SetSliderDialogDefaultValue(float value)
function SetSliderDialogRange(float minValue, float maxValue)
function SetSliderDialogInterval(float value)

-- Events: --

; Dialog open
event OnOptionSliderOpen(int option)

; Dialog accept
event OnOptionSliderAccept(int option, float value)

; Highlight
event OnOptionHighlight(int option)

; Default
event OnOptionDefault(int option)

-- Example: --

 

; OID
  int frequencyOID_S    ; _S for slider
  int durationOID_S     ; _S for slider

; State
  float frequency = 2.0
  float duration  = 1.5


EVENT OnPageReset(string page)
    frequencyOID_S = AddSliderOption("How often?", frequency, "Every {0} days")
    durationOID_S  = AddSliderOption("How long?",   duration, "For {1} hours")
ENDEVENT


EVENT OnOptionSliderOpen(int option)
    if (option == frequencyOID_S)
        SetSliderDialogStartValue(frequency)
        SetSliderDialogDefaultValue(2.0)
        SetSliderDialogRange(1.0, 14.0)
        SetSliderDialogInterval(1.0)

    elseIf (option == durationOID_S)
        SetSliderDialogStartValue(duration)
        SetSliderDialogDefaultValue(1.5)
        SetSliderDialogRange(1.0, 24.0)
        SetSliderDialogInterval(0.5)
    endIf
ENDEVENT

EVENT OnOptionSliderAccept(int option, float value)
    if (option == frequencyOID_S)
        frequency = value
        SetSliderOptionValue(frequencyOID_S, frequency, "Every {0} days")

    elseIf (option == durationOID_S)
        duration = value
        SetSliderOptionValue(durationOID_S, duration, "For {0} minutes")
    endIf
ENDEVENT

 

 

 

You wrote:"trying to put a slider about level mult, which has the range of 0 to 5 with the interval of 0.05."

    SetSliderDialogStartValue(0)
    SetSliderDialogDefaultValue(1)
    SetSliderDialogRange(0, 5)
    SetSliderDialogInterval(0.05)
Edited by ReDragon2013
Link to comment
Share on other sites

Are you changing it in both the AddSliderOption and SetSliderOption (or their state versions if you the state method)?

Â

Both might need to be identical in order to work properly. Cannot say for sure as the only sliders I have set up used a step interval of 1.0 and I had no need to change the default value of the FormatString parameter.

Yes, i edited both of them with the same changes i put in the main post. I tried to look for example from other mods which have have at least a single slider with a float stringFormat value but couldn't find it (at least from the mods i got my hands into).
Link to comment
Share on other sites

The number inside the brackets sets the decimal places:

A value of 1 with format string {2} is displayed as 1.00.

A value of 2 with format string {1} is displayed as 2.0.

 

I think this is what I've been looking for. I didn't actually know how to utilize the brackets {} to properly show the exact value i want. I thought that i can just put (.) into the number inside the brackets to show a float value, but it didn't seem to be the case.

 

Alright, I'll try it later. I'll post my reply again if i get another problem about this matter. Thank you very much. :)(Unfortunately i can only try it next Tuesday due to my pc is in repair and will be done at Tuesday)

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...