7.1rc3, set $variable or set variable in system/script

In CLI/Terminal this works perfect. Global “WAN1DownCounter” is increase itself in every run that code in CLI.

if ([len [system/script/environment/find name=WAN1DownCounter ]] = 0 ) do={ global WAN1DownCounter 1 } else={ set WAN1DownCounter value=([system/script/environment/get WAN1DownCounter value]+1) }

:
But if I create a script1 with that code and run it at 7.1rc3 then it’s not work properly.

system/script/run script1
syntax error (line 1 column 115)

When I change problematic set WAN1DownCounter to set $WAN1DownCounter then it’s start working… but still not proper. He create global but not inc it value. No more syntax error.

@rextended Please help :slight_smile:

Try this:

:global WAN1DownCounter;
:if ([ :typeof $WAN1DownCounter ] = "nothing") do={
  :set WAN1DownCounter 1;
} else={
  :set WAN1DownCounter ($WAN1DownCounter + 1);
}

Ohhh… call me on topic where already I have wroted :slight_smile:

NOw I read and reply to your post

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)
}
  1. 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)
}
  1. 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.

Thanks for answers !
Sorry but OP cannot put both SOLVED

No problem, but in my post I also put in the explanations :stuck_out_tongue:

About @eworm soluction:
is pretty the same:
I check if is it a number, because MUST be a number, if is it I add one, else I set to 1 the variable
instead @eworm check if is “nothing”, and if is it set to 1 the variable, else add one

Thank you for a “learning style” and other your feedback in my other ones scripts!