How do I handle multiple parameters in a function?

0 favourites
  • 7 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • Functions mystify me. I get the bare basic functionality of a function, but how would I properly use a function with multiple parameters? Does anyone have any samples I could look at?

  • I'd suggest taking a look at the manual page for the function object. In the dialog box that appears when you add the Call function action there's a button labeled Add parameter that will add a field to pass a parameter. It appears that you can add as many as you want. You can then access these parameters by getting the param expression while passing in the zero-based index of the parameter you want.

  • I saw the manual entry for it, but I guess the part I'm stuck on is how those parameters actually get passed around. Like what does it actually look like to assign something to param 0, param 1, etc. To utilize it, it'd look something like function(x,y,z), but how do I tie x, y, and z to the contents of the function? Via local variable?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Use Function.Param(0), Function.Param(1), etc. I tend to pop all params into local variable on the first action to get them named.

  • I saw the manual entry for it, but I guess the part I'm stuck on is how those parameters actually get passed around. Like what does it actually look like to assign something to param 0, param 1, etc. To utilize it, it'd look something like function(x,y,z), but how do I tie x, y, and z to the contents of the function? Via local variable?

    Here's an example of calling a function with params, using them in the function, and using the returned value (if any).

  • Very nice! I'll play with this info when I get to my PC later today. I greatly appreciate it.

    By the way, do functions need to be recursive to repeat/maintain variable changes, or would the following work:

    If key_pressed then do function()

    Where function can control player speed, direction, movement, sprite for walking, etc.

  • Global variables maintain their value. Local variables don't, by default, so you have to make them 'static'. Hope that's what you're after. You can make functions recursive but I wouldn't unless you know what you're doing

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