Failover script work in terminal, but not in scheduler

Hi guys! =)

I started to use MikroTik several months ago and I loved it so much. )
Just would like to ask from community about configuration of my failover scripts.

Brief overview of situation:
3 WAN interfaces
1 LAN interface

i have load balancing working via these 3 interfaces.
also i have 4 scripts to check which WAN interfaces are available and which are not available:
3 scripts are pinging 50 times the dst-address 8.8.8.8 via corresponding WAN-interface and push the number of successfully transferred pings to the corresponding global variable.
The last script (4th one) is switching on or off gateways (in /ip route) based on information stored in global variables.
I run all 4 scripts each 1 minute (via /system scheduler)

The problem is: the script #4 working when i run it in Terminal window, but not when it is called from scheduler.
Please help me to make it work from scheduler as from terminal window.

Here are the scripts:

This one is checking first WAN interface
/system script add name="Failover_08FastNet-vlan-check" source={
:global FNVcount [ping 8.8.8.8 interface=08FastNet-vlan count=50];
if ($FNVcount <= 45) do={
:global FNVcheck "down"
} else={
if ($FNVcount >= 45) do={
:global FNVcheck "up"
}
}
}

This one is checking the second WAN interface
/system script add name="Failover_10KT-check" source={
:global KTcount [ping 8.8.8.8 interface=10KT count=50];
if ($KTcount <= 45) do={
:global KTcheck "down"
} else={
if ($KTcount >= 45) do={
:global KTcheck "up"
}
}
}

This one is checking the third WAN interface
/system script add name="Failover_09FastNet-check" source={
:global FNcount [ping 8.8.8.8 interface=09FastNet count=50];
if ($FNcount <= 45) do={
:global FNcheck "down"
} else={
if ($FNcount >= 45) do={
:global FNcheck "up"
}
}
}

This script is enabling/disabling the gateways based on information which of them are available now and have good connection
/system script add name="Failover_switch-lines" source={
:local rNumber [/ip route find where dst-address=0.0.0.0/0];
if ($FNcheck="up" && $KTcheck="up" && $FNVcheck="up") do={[/ip route set $rNumber gateway=95.215.244.177,91.205.51.1,192.168.1.1]; /log info "Failover: FN-up KT-up FNV-up"};
if ($FNcheck="up" && $KTcheck="up" && $FNVcheck="down") do={[/ip route set $rNumber gateway=95.215.244.177,192.168.1.1];/log info "Failover: FN-up KT-up FNV-down"};
if ($FNcheck="up" && $KTcheck="down" && $FNVcheck="up") do={[/ip route set $rNumber gateway=95.215.244.177,91.205.51.1];/log info "Failover: FN-up KT-down FNV-up"};
if ($FNcheck="up" && $KTcheck="down" && $FNVcheck="down") do={[/ip route set $rNumber gateway=95.215.244.177];/log info "Failover: FN-up KT-down FNV-down"};
if ($FNcheck="down" && $KTcheck="up") do={[/ip route set $rNumber gateway=192.168.1.1];/log info "Failover: FN-down KT-up FNV-down"};
if ($FNcheck="down" && $KTcheck="down") do={
/log info "Failover: FN-down KT-down FNV-down";
if ($FNcount >= KTcount) do={[/ip route set $rNumber gateway=95.215.244.177]; /log info "Failover: FNLink - primary now"};
if ($FNcount < KTcount) do={[/ip route set $rNumber gateway=192.168.1.1]; /log info "Failover: KTLink - primary now"};
}
}

Too heavy solution I would say. Why not to have all default routes set and just change the distance via netwatch script?

Because this solution gives following advantages:

  1. Load balancing: traffic is flowing through all available WAN interfaces
  2. Quality of service: when system is getting packets loss more or equal of 10% on any of WAN interfaces it disables these WAN interfaces (which having packets loss)

And the actual question is about this script:
:local rNumber [/ip route find where dst-address=0.0.0.0/0];
if ($FNcheck=“up” && $KTcheck=“up” && $FNVcheck=“up”) do={[/ip route set $rNumber gateway=95.215.244.177,91.205.51.1,192.168.1.1]; /log info “Failover: FN-up KT-up FNV-up”};
if ($FNcheck=“up” && $KTcheck=“up” && $FNVcheck=“down”) do={[/ip route set $rNumber gateway=95.215.244.177,192.168.1.1];/log info “Failover: FN-up KT-up FNV-down”};
if ($FNcheck=“up” && $KTcheck=“down” && $FNVcheck=“up”) do={[/ip route set $rNumber gateway=95.215.244.177,91.205.51.1];/log info “Failover: FN-up KT-down FNV-up”};
if ($FNcheck=“up” && $KTcheck=“down” && $FNVcheck=“down”) do={[/ip route set $rNumber gateway=95.215.244.177];/log info “Failover: FN-up KT-down FNV-down”};
if ($FNcheck=“down” && $KTcheck=“up”) do={[/ip route set $rNumber gateway=192.168.1.1];/log info “Failover: FN-down KT-up FNV-down”};
if ($FNcheck=“down” && $KTcheck=“down”) do={
/log info “Failover: FN-down KT-down FNV-down”;
if ($FNcount >= KTcount) do={[/ip route set $rNumber gateway=95.215.244.177]; /log info “Failover: FNLink - primary now”};
if ($FNcount < KTcount) do={[/ip route set $rNumber gateway=192.168.1.1]; /log info “Failover: KTLink - primary now”};
}\

When i run it via terminal - it works
When i run it via scheduler - it doesn’t

May be someone can say why it happens so? and how i can fix it

Problem is solved
I moved the content of script inside the Scheduler
Previously I called execution of the script from Scheduler by it’s name.

Thanks to everyone for reviewing and wish to help.