I would write it similar to this:
dim ObjectXpos(2)
ObjectXpos(1)=0
ObjectXpos(2)=0
A_func_running=0
B_func_running=0
Do
if Upkey()=1 and A_func_running=0 then A_func_running=1
if Downkey()=1 and B_func_running=0 then B_func_running=1
if A_func_running=1 then A_func_running=UpdateFunc(1,0.1,10)
if B_func_running=1 then B_func_running=UpdateFunc(2,-0.1,-10)
sync
loop
End
function UpdateFunc(obj,move,limit)
if (ObjectXpos(obj))^2>limit^2
exitfunction 0
else
ObjectXpos(obj)=ObjectXpos(obj)+move
position object obj,ObjectXpos(obj),0,0
endif
endfunction 1
Then I have only one multi-use function, rather than two (or more) gosubs. The function can be passed any object number, with a move rate and a limit.
If the square of the objectpos is greater than the square of the limit, the function stops, returning a value of 0. I check for the square so I don't have to check for xpos>limit if move +ve or xpos<limit if moving -ve.
If the xpos squared is greater than the limit squared the function returns 0, this gets assigned to either flag (A_func_running or B_func_running), resetting them so they can run again later.
If not, the xpos gets updated, and the object moved, and then the function returns 1, which keeps the flag going.
Hope this shows yu the power of the function! It is your friend, and will become the centre of your coding!