 |
|
 |
 | The Ins and Outs of Functions |  |
Trimis: 06/07/2007 09:42 |
|
|
| Ad_Infinitum |
| Administrator |

 |
 |
| Data inscrierii: 23/Iun/2007 |
| Mesaje: 212 |
|
|
|
 |
 |
 |
|
remstart
Functions Example 3
In the first example, our value remained static, no matter how many times we incremented it.
By passing in the value as a paremeter, and receiving it back again afterwards,
the value can be retained. In a real programming situation, you might use this
feature of functions to calculate a new character position,
evaluate health based on numerous factors (or parameters), or simply perform a
long-winded calculation that is "tidier" in the form of a function.
remend
` Basic Setup
`******************************************************
set display mode 640,480,16
sync on: sync rate 10
` Main routine
`******************************************************
` Call the function Counter() 1000 times
for looping = 1 to 1000
cls
MainValue = Counter(MainValue)
center text 320, 200, "Main Code : I have looped " + str$(looping) + " times"
center text 320, 420, "Press 'Esc' to Exit"
if escapekey() then end
sync
next looping
` End Program
`******************************************************
end
`******************************************************
` Functions
` Functions always appear after the main body of your code.
` Although there is an "end" statement above for completeness,
` it is not essential. Your functions will NOT run, until
` you call them explicitly. This is the first major difference
` between Subs and Functions.
`******************************************************
function Counter(MyValue)
` Increment the value of n, and display
inc MyValue, 1
center text 320, 240, "Function : I have incremented MyValue, it's value is now " + str$(MyValue)
endfunction Myvalue
---------------------------------ScreenShot----------------------------------
 |
|
|
|
|
|
|
Fa-ti si tu propriul forum GRATUIT, pe www.myforum.ro
|
|