My own functions

Game Editor comments and discussion.

My own functions

Postby asmodeus » Mon Nov 26, 2007 2:20 pm

Can I make my own function? If I can, how can I make them?
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score

Re: My own functions

Postby Game A Gogo » Mon Nov 26, 2007 5:58 pm

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';"
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Re: My own functions

Postby Fuzzy » Mon Nov 26, 2007 8:50 pm

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.
Mortal Enemy of IF....THEN(and Inspector Gadget)

Still ThreeFingerPete to tekdino
User avatar
Fuzzy
 
Posts: 1068
Joined: Thu Mar 03, 2005 9:32 am
Location: Plymostic Programmer
Score: 95 Give a positive score

Re: My own functions

Postby asmodeus » Tue Nov 27, 2007 1:56 pm

Thanks very much!
User avatar
asmodeus
 
Posts: 483
Joined: Thu Oct 11, 2007 5:04 pm
Location: Germany
Score: 43 Give a positive score


Return to GE - General

Who is online

Users browsing this forum: No registered users and 1 guest

cron