Page 1 of 1

My own functions

PostPosted: Mon Nov 26, 2007 2:20 pm
by asmodeus
Can I make my own function? If I can, how can I make them?

Re: My own functions

PostPosted: Mon Nov 26, 2007 5:58 pm
by Game A Gogo
Yes you may, go in the global code editor and then you can follow these:
Code: Select all
void()//If you need any params to entered, declare the vars in the "()"
{
    //Code here
}
//Void should be used if you don't need the function to return something.
//But if you need the function to return something, use like char, double, float or int and use the "return 10.1;" or for a char "return 'a';"

Re: My own functions

PostPosted: Mon Nov 26, 2007 8:50 pm
by Fuzzy
the format is set like this
Code: Select all
type function_name(parameters)
{
     body of function
};


type is either void or a type of variable, integer, float, double, char, string. if the body of the function contains a return statement, it will return a variable of the type specified before the function name.

Function name is anything you want other than key words that are already defined in C or GE.

Parameters are passed variables. They are more like place holders telling GE what to expect in those places. I'll give an example in a little bit.

the body of the function contains whatever code you need. IF you dont use void, you will need a return statement(at least one).

Here is a dummy Function
Code: Select all
int check_answer(int answer)
{
    if (answer == 5)
    {
        return 1;
    }
    else {return 0;}
};

to use it, you do this elsewhere in the program
Code: Select all
mark = mark + check_answer(Five);

note that five is could be a function as well, as long as it returned an int. Otherwise use a variable.

Re: My own functions

PostPosted: Tue Nov 27, 2007 1:56 pm
by asmodeus
Thanks very much!