what's wrong with that script

I wrote a script to calculate the quantity withdrawn from the client and that is different in a minute script to withdraw the name of the client and the division of the speed limit on them evenly in the queue Simple
What is wrong with the code I hope illustration

here is mine

:global active
:global uspeed 8100
:global dspeed 2048
:global maxu
:global maxd
/ip hotspot active ;\
:foreach nm in=[find]\
do={\
:global byte1 [get $nm bytes-out]
}
:delay 1m
/ip hotspot active ;\
:foreach nm in=[find]\
do={\
:global byte2 [get $nm bytes-out]
:global bytenew ($byte2 - $byte1)
:if ($bytenew > 15000000)\
do={\
:global nm 0
:set active [:len $nm]
:set maxd (($uspeed / $active)*1000)
:set maxu (($dspeed / $active)*1000)
:global ip [get $nm address]
:global mind [get $nm user];\
/queue simple ;\
remove [find name=$mind] ;\
add burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s comment=newmind direction=both disabled=no \
    interface=all limit-at="$maxu/$maxd" max-limit="$maxu/$maxd" name=$mind packet-marks="" parent=none priority=4 \
    queue=default-small/default-small target-addresses=$ip total-queue=default-small;\
remove [find name!=$mind] ;\
}}}

First of all, your first for loop ends right there. It runs through each active item in the hotspot, and just keeps reassigning the global variable until it gets to the last entry.

I’m not really clear on what you are trying to do, but you will need to, at the very least, extend out the first for loop to a greater scope.

But the downside to the script that you have written is that it will take more than a minute for each entry in the hotspot to run and loop through everything, and it can only work on one entry at a time. I’m not sure there is a good way to script what you want to do. You might be able to use the new “function” feature in 6.2 or greater and pass the current byte1 to that function and have the delay, calculation, and adjustment in that script. I’m just not sure if there is a limit on how many times a script/function can be called in a row.

Further to this, PCQ was created for performing this same function automatically (dividing available bandwidth between online users in an address pool etc), have a read of the following and watch the video presentation if you want to learn more:

http://mum.mikrotik.com/presentations/US11/us11-megis.pdf

http://www.tiktube.com/video/mJeK3iHGhLKLIKImpnCsFrHvnlIomlpG=