:global, :local and :set do not want $,
if you want "set" something inside array like
:set ($array->"item") "value" apparently you must use $ in front of variable,
but really at that point the "name" of the variable is "passed" from the function (...) and you use the $ because the variable is inside the function (->)
I can make mistakes too, RouterOS is quite forgiving with syntax errors,
but then sometimes things don't work as expected anymore when they fix some problem, or whatever...
better to write immediately with the correct syntax...
some error check for understand
unusable debug code
{
# added path for avoid multiple time same string
/ppp active
:local allowed 3
:local scount 0
# removed useless quotes
:local nama "$user"
:local nama $user
# removed path for avoid multiple time same string
:local sess [/ppp active find where name=$nama]
:local sess [find where name=$nama]
# already $sess is [find where name=$nama], why call it again???
# (also missing where on previous line)
# not fixed now: this line potentially can do error if is present more than one ppp session with same name
:local callerid [get [/ppp active find name=$nama] caller-id]
:local callerid [get $sess caller-id]
# removed useless end space
:log warning "PPP User ($nama) Logged in from $callerid "
:log warning "PPP User ($nama) Logged in from $callerid"
# removed big error: space between = and variable
:foreach sessid in= $sess do={
:foreach sessid in=$sess do={
# after :set, $ must not be used
:set $scount ($scount + 1)
:set scount ($scount + 1)
# noerror: or put a space on both sides, or not on both sides.
:if ($scount <= $allowed ) do={
:if ($scount <= $allowed) do={
:log warning "Session ($scount) find for User: ($nama) is ($sessid) Allowed!"
} else={
# removed path for avoid multiple time same string
# added missing where
/ppp active remove [find session-id=$sessid]
remove [find where session-id=$sessid]
:log error "Session ($scount) find for User: ($nama) is ($sessid) not Allowed and disconnected!"
}
}