Ok, little "tutorial"
1) please proper indent, and use the : and / everityme!
:if ([:len [/system/script/environment/find where name=WAN1DownCounter]] = 0) do={
:global WAN1DownCounter 1
} else={
:set WAN1DownCounter ([/system/script/environment/get WAN1DownCounter value] + 1)
}
2) the right way to use a variable is to call it directly, not searching everytime on environment
why not work: before run the ":if" the ":set WAN1DownCounter" can not find "WAN1DownCounter" because is undeclared.
Soluction: delcare it (:global WAN1DownCounter do not assign any value, and do not alter it if is already set)
:global WAN1DownCounter
:if ([:len $WAN1DownCounter] = 0) do={
:global WAN1DownCounter 1
} else={
:set WAN1DownCounter ($WAN1DownCounter + 1)
}
3) but now we have another problem, the first time is run do error because undefined variable + 1 fail
the soluction is check first if WAN1DownCounter is a number, if not set it to 1, if yes add 1 to actual value:
:global WAN1DownCounter
:if ([:typeof $WAN1DownCounter] = "num") do={
:set WAN1DownCounter ($WAN1DownCounter + 1)
} else={
:set WAN1DownCounter 1
}
Done.