Hi, if I write this global variable: :set currentStateDSL1 [:len [/ip route find gateway=$gatewayDSL1 dst-address=$dstAddressDSL1 routing-table=main active=yes]];
This returns a 1 (or a 0 in case of error).
But if I enter it this way: :set currentStateDSL1 1;
it does not work:
:if (($currentStateDSL1 = 1) and ($previousStateDSL1 = 0)) do={...
Under "Enviroment" (Scripts) is in both ways a "1" displayed. But the ":set currentStateDSL1 1;" is not working?!
One error after another...
Variables must be declared first
in front of global and local must be used ":" (or "/" )
after :set don't put the $ (except arrays)
if run from the command line, the script requires to be enclosed on parentheses { }
useless ; are useless ;
:len return a number, not one string
@Guscht
As usual, without seeing the entire script, we can only speculate. For example, is $previousStateDSL1 present? When is it defined? How? It's also in the conditional; without specifying it, the topic's question doesn't make sense either.
And what does "not working" mean? It doesn't make any sense without explaining what's not working. What's not working? Your TV won't turn on?
Untested (for obvious reason) script example: (enclose all on { } for try it on terminal)
:global currStateDSL1 ; :if ([:typeof $currStateDSL1] = "nothing") do={:set currStateDSL1 0}
:global prevStateDSL1 ; :if ([:typeof $prevStateDSL1] = "nothing") do={:set prevStateDSL1 0}
:local gatewayDSL1 <...>
:local dstAddrDSL1 <...>
# debug lines, remove after tests...
:set currStateDSL1 1
:log info "DEBUG: currStateDSL1 is $currStateDSL1 of type $[:typeof $currStateDSL1]"
# debug end
:set currStateDSL1 [:len [/ip route find where gateway=$gatewayDSL1 and dst-address=$dstAddrDSL1 and routing-table=main and active=yes]]
:log info "Return Lenght of the Find is $currStateDSL1 of type $[:typeof $currStateDSL1]"
:if (($currStateDSL1 = 1) and ($prevStateDSL1 = 0)) do={
# the DSL go from 0 to 1
:log info "currStateDSL1 is 1 and prevStateDSL1 is 0"
} else={
# the DSL NOT go from 0 to 1, so it covers all other cases:
# still offline 0 / 0
# still online 1 / 1
# go offline 1 / 0
:log info "currStateDSL1 is not 1 or prevStateDSL1 is not 0"
}
:set prevStateDSL1 $currStateDSL1