Issue with slider behaviour - click release changes the value

Pachovski
Pachovski Member Posts: 3 Newcomer
edited October 2024 in Scripting Workshop

Hey guys,
I have an issue with a slider (reverb volume in my case, although I don't think it's relevant).
When I click the slider, adjust the value and I see the value changing in a display label. However when I release the mouse click the value changes a little.
While trying to explore the issue I figured out that if I'm turning the volume up…the value I get after the mouse-click release is a bit higher than shown before (ex. start from -inf turn it up to -17.4 dB and after click release the value jumps to -15.6).
Similar thing is happening while turning the volume down - then after the click release I get a lower value than before the click release.

Can anybody suggest how to fix this issue?
Is it a make_persistent/read_persistent thing that I've done wrong?

Thanks in advance!

Comments

  • theodorech
    theodorech Member Posts: 72 Member

    It'd be code conflict, poor value scaling, mouse_behavior or anything. It's hard to judge without seeing the code :)

  • Pachovski
    Pachovski Member Posts: 3 Newcomer
    on init
    declare ui_slider $sli_reverb_vol (0, 500000)
    set_control_par ($sli_reverb_vol, $CONTROL_PAR_MOUSE_BEHAVIOUR, -2500)
    set_control_par ($sli_reverb_vol, $CONTROL_PAR_DEFAULT_VALUE, 200000)
    make_persistent($sli_reverb_vol)
    read_persistent_var($sli_reverb_vol)
    set_engine_par($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN, $sli_reverb_vol, -1, 6, 0)
    declare ui_label $lbl_rev_vol_read (1, 1)
    set_text($lbl_rev_vol_read, $sli_reverb_vol & " dB")
    hide_part($lbl_rev_vol_read, $HIDE_PART_BG)
    set_control_par(get_ui_id($lbl_rev_vol_read),$CONTROL_PAR_FONT_TYPE,25)
    set_text($lbl_rev_vol_read, get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN, -1, 6, -1) & " dB")
    end on on ui_control($sli_reverb_vol)
    set_engine_par($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN, $sli_reverb_vol, -1, 6, 0)
    set_text($lbl_rev_vol_read, get_engine_par_disp($ENGINE_PAR_SEND_EFFECT_OUTPUT_GAIN, -1, 6, -1) & " dB")
    end on


    Both slider and label I've declared with a macro containing the position, sizes, image, etc. but I'm not able to paste the code properly… However this is what actually goes in the macro but broken down.

    In the "on ui control" part I've tried adding a wait(10000) and then set_text with the exact same line of code in order to fix the issue, assuming the issue was result of fast turning of the knob… however the problematic behaviour is the same.

  • theodorech
    theodorech Member Posts: 72 Member

    I just tried your code, and it works fine, no lag or weird values. Double check if any other code is causing conflicts when you display the value on the screen or if your slider is linked to any MIDI CC automation.


    By the way, the group-slot-index values should be the same in both set_engine_par and get_engine_par_disp. It might not change anything in your current example, but it's a good practice for your future KSP projects. :)

  • Pachovski
    Pachovski Member Posts: 3 Newcomer

    Thanks for the tip, definitely will have this in mind (group-slot-index values).

    Also…I will try to get rid of the macro creating the slider and label and try creating them manually…maybe there's something that is not precise in the macro, although all the other 15-20 buttons/sliders/labels in the library are created the same way and they seem to be working as expected.

  • theodorech
    theodorech Member Posts: 72 Member

    There's probably an issue in your script. If everything else is working fine, the problem is likely with the callback for your reverb slider. The code snippet you sent me works as expected. Are you sure no other callback is using the same code to display values? Maybe when you copied and pasted the code for the other UI callbacks, you left something related to the reverb slider. Right now, it's a bit of a guessing game since, as you mentioned, there are many more elements than just the slider.

This discussion has been closed.
Back To Top