The variables inside the function are local variables (they are not the same as those outside of the function). You could pass the variables to the function like this:
repeat
draw_ball(ball(1),ball(2),ball(3),ball(4))
sync
until escapekey() = 1
end
function draw_ball(ball1,ball2,ball3,ball4)
sprite 1, ball1, ball2, 1
ball3 = ball1
ball4 = ball2
endfunction boll
Since the arrays in the main program and in the function are not the same, I changed the names slightly to avoid confusion. If you wanted to, you could re-dimension the arrays within the function.
In your code, you really are not passing a variable to the function, nor are you returning one. i.e. you're not really taking advantage of the function capabilities. I would recommend until you get further along in understanding global versus local variables that you consider just using a subroutine instead of the function. Something like this:
repeat
gosub draw_ball
sync
until escapekey()=1
end
draw_ball:
ball(3) = ball(1)
ball(4) = ball(2)
sprite 1, ball(1), ball(2), 1
return
I would suggest putting the sprite drawing at the end of your routine, instead of at the beginning, that way if you make changes to the variables it will show up in the drawn sprite.
The code really does not do anything with the ball, but I assume you'll put that in later.
Also, you need to declare a sync rate.
You idiots! You've captured their stunt doubles!