1. IMPORTANT:
    We launched a new online community and this space is now closed. This community will be available as a read-only resources until further notice.
    JOIN US HERE

Display ratio slider

Discussion in 'Scripting Workshop' started by Aderre, May 29, 2014.

  1. Aderre

    Aderre Member

    Messages:
    33
    Hi, is there a way to specify a slider's display ratio? If yes, where is it written in KSP? Thanks
     
  2. EvilDragon

    EvilDragon Well-Known Member

    Messages:
    19,938
  3. Aderre

    Aderre Member

    Messages:
    33
    Well, I finally got it to work like this, for if someone is interested:

    This tune knob is inside the Midi Echo preset from the NI scripts, that's why it's not with engine parameters.

    The original string for the parameter is

    lb_Tune is the lable for the $Tune, which is a slider.

    As you can see, the parameters for the $Tune slider are from -100 to 100.
    When it goes negative, usually with the code above (without the *-10) you would get something like -0.-10 and so on, that's why you require to multiply it by -10, because then it becomes plus even being minus in theory, and then you divide it because only with the multiplication it becomes something like -0.010000
    you divide it with the amount of zeros you want taken out of that.
    When going down until -9, it will look like -0.9 instead of -0.09. to fix this, I had to add all the cases with if, because i am not good yet with coding. Just check the example above, in these cases, you got to specify
    this before the parameter
    with this way you will obtain that missing zero. When you arrive to the total minimum (-100) you have to make another division, so instead of looking like -0.100 it will look like -1.00. You can do so by dividing the number to a single number, like in this case 1, then adding
    after the concrete paremeter
    In the case of the plus 100, the things are easier. You just have to divide the amount you have with a number that gets you a number like the one you want. For example, if you want to have 0.10 then you should divide 10000 by 1000, and then add the
    expression before the concrete parameter
    If the main amount is 10000 and you divide it by 1000, you will also get numbers like 1,2,3,4,5,6,7,8,9. These numbers won't automatically be like 0.09, instead, they will look like 0.1 / 0.2 / 0.3 etc. That's why you need to specify, that from 0 to 9, instead of a simple
    you should put a
    to get that missing zero. From 10 on,
    is enough, although when you get to the final point, which would be 100, you will get it like 0.100 if you leave it like this, so you have to specify, that when the knob reaches the parameter (in this case 100), then it requires a division to become a normal 1, and then you add
    after the concrete paremeter
    so it will look like 1.00 in the end.

    I know my explaining is chaotic, but english isn't my main language, so this is all i can squeeze out of my knowledge.
     
  4. Big Bob

    Big Bob Forum Member

    Messages:
    606
    If you have my math library, you may want to take a look at the function named DFmtVal(val,dd). This function will return a string version of val formatted with dd decimal digits.

    This function is very handy for custom formatting and/or simulation of the display ratio for slider values.

    Rejoice,

    Bob