Diference betwen function types?

You must understand the Game Editor concepts, before post here.

Diference betwen function types?

Postby Novice » Thu Jun 01, 2006 9:53 pm

Hi everybody,
I just recently started defining my functions and i was wondering what diference is there when defining functions with void, int or something else?
I tried making the same function int and void and both ways it worked just fine. My guess is that void functions don't return results but int do, am i wrong? :?
If anybody is willing to explain or point somewhere i'd be gratefull.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby plinydogg » Thu Jun 01, 2006 10:09 pm

Novice,

I'm no expert but I think you're basically right.

I use void functions if I just need stuff done but don't need anything else

Ex:

void changeAnimation()
{
ChangeAnimation("actor", "picture", NO_CHANGE);
}

I use int functions if I need an integer value. You use "return" to tell the function what int to return.

Ex:

int checkLightStatus()
{
if(lightPosition.text == "on")
{
return 1;
}
else
{
return 0;
}
}

Then you can use the checkLightStatus() function in other scripts.

ex:

in the script editor of a mouse down event on an actor called lightSwitch...

if(checkLightStatus()==1)
{
strcpy("lightPosition.text", "off");
}

The int and void varieties are the only type of functions I use, so I can't comment on the others....
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby Novice » Thu Jun 01, 2006 10:20 pm

Thank you very much plinydogg :mrgreen: .
That helped a lot, now i won't have to use exces variables wich i realy didn't need.
If anyone knows anything about other types, please don't be shy it's for the common good :wink: .
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby plinydogg » Thu Jun 01, 2006 10:28 pm

Also, let me know if you need to know the basics about passing parameters to functions.
plinydogg
 
Posts: 104
Joined: Thu Aug 25, 2005 8:34 pm
Score: 0 Give a positive score

Postby Novice » Thu Jun 01, 2006 10:41 pm

Code: Select all
int multiply(int a,int b)
{
int res;
res=a*b;
return res;
}

Did you mean that? Is this code right? Will it return the name "res" or the result of a*b? Because i tried
Code: Select all
textNember=multiply();

and that's no good.
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score

Postby Novice » Thu Jun 01, 2006 10:45 pm

Ok, im kinda stupid. :oops:
This worked
Code: Select all
textNumber=multiply(5,4);
Why do i always get stuck?
User avatar
Novice
 
Posts: 399
Joined: Mon Aug 29, 2005 10:54 am
Location: Relative
Score: 5 Give a positive score


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest