Page 1 of 1

Diference betwen function types?

PostPosted: Thu Jun 01, 2006 9:53 pm
by Novice
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.

PostPosted: Thu Jun 01, 2006 10:09 pm
by plinydogg
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....

PostPosted: Thu Jun 01, 2006 10:20 pm
by Novice
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: .

PostPosted: Thu Jun 01, 2006 10:28 pm
by plinydogg
Also, let me know if you need to know the basics about passing parameters to functions.

PostPosted: Thu Jun 01, 2006 10:41 pm
by Novice
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.

PostPosted: Thu Jun 01, 2006 10:45 pm
by Novice
Ok, im kinda stupid. :oops:
This worked
Code: Select all
textNumber=multiply(5,4);