# How to Bypass a Script?



## peterwilson (Jul 9, 2010)

Hi,

I'm a bit stuck on this one. Does anyone know how to bypass a script?

Here is an example of what I mean:

*on init
declare ui_button $BYPASS
end on

on ui_control ($BYPASS)
if ($BYPASS = 1) 
***[enable bypass of script number 2]***
else
*** [disable bypass of script number 2]***
end if
end on*

I've starred the bit that I don't know how to code. I've searched the manual and google searched, but everything I find seems to refer to bypassing sections in the same script. I'm trying to bypass another script. There is a "bypass" button on the script editor, but I'd like to get it in the GUI if I can. 

I'm hoping that someone clever on here might know the answer!

Thanks


----------



## EvilDragon (Jul 9, 2010)

You can't bypass another script from one script, there's no directive to do that, AFAIK...


----------



## peterwilson (Jul 9, 2010)

Ah thanks - at least I know to stop searching now!


----------



## Reegs (Jul 10, 2010)

Something like this:


```
{script 1 -- place in slot 1}
on init
    
    declare ui_switch $bypass_script2
    set_text ($bypass_script2,"Bypass Script 2") 
    declare $slot1_bypass_state := 0
    
    make_perfview
    declare $x
    pgs_create_key(SCRIPT_SLOT_ACTIVE, 5)
    $x := 0
    while ($x <= 4)
    pgs_set_key_val(SCRIPT_SLOT_ACTIVE,$x,1)
    inc($x)
    end while
   
end on

on ui_control ($bypass_script2)
    if ($bypass_script2 = 1)
    pgs_set_key_val(SCRIPT_SLOT_ACTIVE, 1, 0)
    else
    pgs_set_key_val(SCRIPT_SLOT_ACTIVE, 1, 1)        
    end if
end on

{Check about Slot 1 state}
{(I put in the key colorings to track them)}
on pgs_changed
    if(pgs_key_exists(SCRIPT_SLOT_ACTIVE))
        if (pgs_get_key_val(SCRIPT_SLOT_ACTIVE, 0)=0)
            $slot1_bypass_state := 1
            set_key_color(45,$KEY_COLOR_RED)
        else
            {continue as normal}     
            $slot1_bypass_state := 0    
            set_key_color(45,$KEY_COLOR_GREEN)
        end if
    else
    end if
end on

on note
    {Pre-check: This sees if the callback should run or if the script should have a disabled state; mirror for on controller and other events}
    if($slot1_bypass_state= 1 )
    {note script slot 1 does not run}
    else
    {note script slot 1 runs}
    {other code}
    end if
end on
```
and for the second slot (and third, fourth):

```
{script 2}
on init
    
    declare ui_switch $bypass_script1
    set_text ($bypass_script1,"Bypass Script 1") 
    declare $slot2_bypass_state := 0
    make_perfview
    
end on

on ui_control ($bypass_script1)
    if ($bypass_script1 = 1)
    pgs_set_key_val(SCRIPT_SLOT_ACTIVE, 0, 0)
    else
    pgs_set_key_val(SCRIPT_SLOT_ACTIVE, 0, 1)        
    end if
end on

{Check about Slot 2 state}
on pgs_changed
    if(pgs_key_exists(SCRIPT_SLOT_ACTIVE))
        if (pgs_get_key_val(SCRIPT_SLOT_ACTIVE, 1)=0)
            $slot2_bypass_state := 1
            set_key_color(55,$KEY_COLOR_RED)
        else
            {continue as normal}     
            $slot2_bypass_state := 0
            set_key_color(55,$KEY_COLOR_GREEN)   
        end if
    else  
    end if
end on

on note
    if($slot2_bypass_state= 1 )
    {Script code in Slot 2 for note callbacks will not run}
    else
    {code for On Note Callback}
    end if
end on
```

Like I said, I'm not sure what the performance hit will be on the callbacks, especially with a lot of simultaneous notes or controller data coming in. I would not expect it to be that much. Depending on how often you expect certain scripts to be bypassed it may make more sense to flip the conditionals I threw into the note callback-- you might improve execution speed, or it may be negligible.


----------

