|
example 1 a function without a return
rem make a function to draw a outlined box function Line_Box(x1,y1,x2,y2) line x1,y1,x2,y1 line x1,y2,x2,y2 line x1,y1,x1,y2 line x2,y1,x2,y2 end function
rem loop repeated boexs on the screen
do rem call our new command Line_Box(rnd(640),rnd(480),rnd(640),rnd(480)) rem update the screen sync rem loop back to do loop
example 2 a function with a return
Rem a function to compare 2 numbers and return the higher one
function High_Compare(n1,n2) if n1 > n2 returnval = n1 endif if n2 > n1 returnval = n2 endif end function returnval
do a = rnd(100) b = rnd(100) print High_Compare(a,b)," " sync loop
Explanation of examples.
Example 1 take 4 arguments to define a rectangle region, transposes those to lines and makes a box. Expand it - can you add another argument to set the box color?
example 2 take 2 arguments and returns the highest value.
Notice how example 1 calls the function just like a command and example example to call it as a function only wanting the return value.
|
|