How do i use function arguments/parameters?

Get help using Construct 2

Post » Tue Jul 16, 2013 3:09 pm

I've been struggling with this programs for a week now and I'm amazed how hard it still is to understand. I have JavaScript background and understand most parts of OOP.

I'm trying to grasp how functions work and in any ordinary programming language you can pass in arguments and then use them inside the called function as parameters. For example:

function setTarget(uid) {
currentTarget = uid;
}

setTarget(id);


In C2 i call a function with a specific name and add a "parameter" (which i guess should be "argument") with the current uid. Inside the function however i wish to use the parameter but have no clue on how to do that?
B
7
S
2
Posts: 38
Reputation: 555

Post » Tue Jul 16, 2013 3:18 pm

Don't worry, functions in C2 are as operational as they are in pure JS.
You can use the function parameter by calling the expression "Function.param(X)", X being the index of the parameter.
I use functions in lots of cases. For example :


(this is explained in a tutorial linked in my signature).
Also, here is a capx I made some times ago to explain the basis of functions.

Finaly, you can take a look at the function reference in the manual. The end of the article will explain all conditions/actions/expressions of the function plugin.
B
17
S
8
G
4
Posts: 461
Reputation: 6,097

Post » Tue Jul 16, 2013 3:20 pm

Function manual entry

I generally use parameters via function.param(number of parameter I want to access) expression.

EDIT: Guizmus was faster, well played Sir :Pvee412013-07-16 15:21:24
B
24
S
9
G
7
Posts: 756
Reputation: 7,292

Post » Tue Jul 16, 2013 3:22 pm

In C2 you have to use the expression param(x) (remember C2 is 0 based so the first parameter passed is param(0), the second param(1), etc...)

So assuming you have not renamed the function object and you want to pick an instance of an object passing its UID to the function, you'd have a condition "Pick object by UID" and have it using function.param(0)

This is the explanation given by the manual article.

Edit: Ninja'd two times ? I'm loosing my touch Kyatric2013-07-16 15:23:55
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
276
S
103
G
84
Posts: 7,289
Reputation: 83,098

Post » Tue Jul 16, 2013 4:04 pm

I see... understand now thanks. Didn't realize it was an index number instead of a name the parameter uses. Thanks! ^^
B
7
S
2
Posts: 38
Reputation: 555


Return to How do I....?

Who is online

Users browsing this forum: wertt22 and 7 guests