I am having trouble coming up with an example to teach someone about functions.
(Funny that I would try to teach something that I barely grasp myself.
)
The example in DBPro help is rather useless.
I want to change a couple of variables outside the function without actually typing them inside the function itself (without the GLOBAL command)
For example, I wanted to use a function to assign a random amount of money then an emotion based on the amount.
I know functions use their own set of variables, but how do I pass the outside ones into the function?
I should know how to do this by now but I can't find any coded evidence that I've ever written a good function.
This is the example is was trying to use, but it doesn't work.
backdrop on
do
if spacekey() then RollerCoaster(Emotion$,Money)
gosub PrintInfo
LOOP
PrintInfo:
set cursor 0,0
print Emotion$
print Money
return
function RollerCoaster(Emtn$,Mny)
Mny=rnd(20000000)-rnd(50000)
if Mny<-500 then Emtn$="Angry"
if Mny>=-500 then Emtn$="Sad"
if Mny>2 then Emtn$="Happy"
if Mny>2000000 then Emtn$="Belligerent"
while spacekey():endwhile
ENDFUNCTION
Once upon a time I thought I understood functions, but I am WAYYYYY behind the curve.