How do I add parameters to a function

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

  • [attachment=0:3a0o335z][/attachment:3a0o335z]

  • thanks LittleStain

  • can You more explain about function in c2 with example. If it is possible

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What kind of example would you want?

    Functions can be used for anything..

  • 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

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

  • 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

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