Function?

Blitz3D Forums/Blitz3D Beginners Area/Function?

most important thing with Functions is when you use a specific Part of Code multiple times then it's better to write a function that can be called as many times as you want.

I guess it was said: Variables n the Main Program (means outside any function) must be defined as Globals if you want to be able to access them inside a Function. Also all Variables you use inside the Function are only Local Variables (unless they are defined as Globals outside the functions), this means their Values are "forgotten" as soon as you end a function.

So to hand over some Variables to a function you can use Globals, or Parameters in the brackets, here the Mouse Position:

setbuffer frontbuffer()
while not keydown(1)
 if mousedown(1)
  drawmouse(mousex(), mousey()) ; << the function call
 endif
wend
end

function drawmouse(x,y)
 plot x,y
end function