How do i use function arguments/parameters?

0 favourites
  • 5 posts
  • 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?

  • 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 :

    <img src="https://www.scirra.com/images/articles/TLE7_2.jpg" border="0">

    (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.

  • 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 :P

  • 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 <img src="smileys/smiley6.gif" border="0" align="middle">

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I see... understand now thanks. Didn't realize it was an index number instead of a name the parameter uses. Thanks! ^^

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)