# How do I add parameters to a function

Get help using Construct 2

### » Sun Jul 27, 2014 4:17 pm

hi all

How do I add parameters to a function such as :

function pow(x: integer , y:integer ){
x: integer
y: integer
pow:integer
for (i = 1 ;i<= y ;i +=1)
pow +=x*y
return pow
}

i want add a parameters for a function in C2 and return value .how i can?
B
4
Posts: 16
Reputation: 222

### » Sun Jul 27, 2014 4:25 pm

You do not have the required permissions to view the files attached to this post.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sun Jul 27, 2014 5:16 pm

thanks LittleStain
B
4
Posts: 16
Reputation: 222

### » Sun Jul 27, 2014 5:23 pm

can You more explain about function in c2 with example. If it is possible
B
4
Posts: 16
Reputation: 222

### » Sun Jul 27, 2014 5:29 pm

What kind of example would you want?
Functions can be used for anything..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sun Jul 27, 2014 6:19 pm

the example does not matter. I want to know how parameter in function used
for example
Create a function detects the distance between two instance from enemy
B
4
Posts: 16
Reputation: 222

### » Sun Jul 27, 2014 7:18 pm

I think probably what you're looking for is function.param(0, 1, etc..) and possibly function.returnvalue

when you call the function, you add the parameters to the function call
they then can be accessed using function.param(0, 1, etc..)
you can also then use function set return value
which can be accessed using function.returnvalue

so like:
function "enemy distance"
calculate distance using function.param(0) and function.param(1)
function set return value to the calculated distance

when you call "enemy distance" send it parameters of the enemies locations or their UIDs (if you want to find their locations from in the function)

okay, my example leaves something to be desired, but is that what you're looking for?
B
88
S
43
G
71
Posts: 601
Reputation: 43,669

### » Sun Jul 27, 2014 7:30 pm

Something like this?

Player on collision with enemy
--Call function "Collission" with parameters
0 - enemy.uid
1 - player.health

on function "Collission"
-- if function.parameter(1) > 10
-- pick enemy with uid = function.parameter(0)
--- enemy destroy
-- if function.parameter(1) < 10
--- player destroy
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775