Axe Software Forums
  Quest Developer Forum
  Confused about Functions


Author Topic:   Confused about Functions
carlii posted 21-05-2002 10:50 BST     
I have been searching all through Quest help for hours and I still don't understand what functions actually are!!

I know they return a value!! That's all anyone can say about them! What really what do they do? Do they calculate something? What's 'parameter' mean? How do I use functions?

In my case, I want the display of a status variable to calculate something as well. This isn't exactly what I've got, but close to it/example is:

You are carrying #weight# grams of weight. Maximum = #max#, (#max#-#weight#) grams of empty space.

The #max#-#weight# in brackets I don't know how to type or calculate! I tried to use a function, so it ended up as:

You are carrying #weight# grams of weight. Maximum = #max#, $rweight$ grams of empty space.

But I don't really know how to edit the rweight function in QDK!!!

I chose 'return a value' and put #max#-#weight#, but then it just says in the display 12000-7000 not 5000 which is the result of that calculation. Do I use a different 'minus' sign?? I'm really confused.

In short, please explain functions properly to me please!!!

Computer Whizz posted 21-05-2002 13:00 BST          
Functions are procedures.....
Procedures are just a set of instructions which are executed in a certain order (top to bottom) and return no value.... EVER! They just execute the instructions.

Functions takes this idea a little further and is used more for maths.
When you say: $function name( parameter1 ; parameter2 )$ the function looks at this call and says:
"That parameter1 goes here and that parameter2 goes there!"

In other words YOU would call $remainingweight_func( #max# ; #wieght# )$
and the function would say:
"parameter1 = #max# param2 = #wieght#"

Now inside the function you can do things with these parameters, multiply them, add them - ANYTHING. Now after you have calculated something, you then return it.

Making a variable called "returnedvalue" you say:
returnedvalue = $parameter(1)$ - $parameter(2)$
return <%returnedvalue%>

Ok?

Computer Whizz