Bypass Switch For ASDR

bassboybenz
bassboybenz Member Posts: 3 Member
edited October 22 in Scripting Workshop

Hi, I'm trying to produce a bypass switch to control the Envelope Bypass.

This is the code that I've been trying to use, but I think I have an error in there?

Any help would be appreciated.


{----Declaring Envelope Bypass Button----}

declare ui_button $Env_Byp

$Env_Byp := 1

declare $Env_Byp_ID

$Env_Byp_ID := get_ui_id ($Env_Byp)

set_text ($Env_Byp,"")

make_persistent ($Env_Byp)

read_persistent_var ($Env_Byp)


move_control_px ($Env_Byp,256,178)

set_control_par_str ($Env_Byp_ID,$CONTROL_PAR_PICTURE,"ds_bypass_button")


on ui_control ($Env_Byp)

if ($Env_Byp=1)

set_engine_par ($ENGINE_PAR_INTMOD_BYPASS,$Env_Byp,1,find_mod(0,"ENV_BYP"),-1)

else 

set_engine_par ($ENGINE_PAR_INTMOD_BYPASS,$Env_Byp,0,find_mod(0,"ENV_BYP"),-1)

end if


end on

Comments

  • Kaiwan_NI
    Kaiwan_NI Administrator Posts: 2,860 admin

    Hi @EvilDragon maybe something for you?

  • corbo-billy
    corbo-billy Member Posts: 106 Helper
    edited October 2022

    The mention "end on" is missing just before the part "on ui_control ($Env_Byp)" _

    And at the very beginning of your script, start with: on init


    Then, you may not see your button ($Env_Byp) so it will be necessary to modify its position in pixels: currently, it is like this. move_control_px ($Env_Byp,256,178) .

    Something else; to see your script when you close the KSP editor, you must write at the very beginning of the script "make_perfview " _

  • Gablux
    Gablux Member Posts: 88 Helper

    there's a few things wrong on the OP's code. And some things that could be optimized:

    on init
        declare ui_button $Env_Byp
        declare $Env_Byp_ID
        $Env_Byp := 1
        $Env_Byp_ID := get_ui_id ($Env_Byp)
        set_text ($Env_Byp,"")
        make_persistent ($Env_Byp)
        read_persistent_var ($Env_Byp)
        move_control_px ($Env_Byp,256,178)
        set_control_par_str ($Env_Byp_ID,$CONTROL_PAR_PICTURE,"ds_bypass_button")
    end on
    on ui_control ($Env_Byp)
        set_engine_par($ENGINE_PAR_INTMOD_BYPASS,$Env_Byp,0,find_mod(0,"ENV_AHDSR"),-1)
    end on
    
    
    
    

    The post was missing the "on init" at the top and the "end on" after the set_control_par_str. No big deal but, please pay attention.

    2nd thing: The string to identify the modulator could be wrong, it was "ENV_BYP". Unless the OP changed manually the name of the modulator, that would not work. By default ADSR modulators have the name "ENV_AHDSR".

    And last but not least, you don't need an if statement. The state of the button is either 0 or 1, you can play directly with that, like I have done on the example above.

    In your version you confused the group argument with the value argument and you had it "1" in one line and "0" on the other, so the function was trying to set the state of the bypass for group "1". Nope nope.

    Use the above instead.

This discussion has been closed.
Back To Top