0 Favourites

How do I choose parameters I want when I call a function?

  • For example, if I call "function" (1,2,3,4,5) but I only want to use parameter 1, 2 and 5

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • You index the parameters. So you would access Function.Param(0) and Function.Param(1) and Function.Param(4) .

  • blackhornet here's what I'm trying to do and I can't figure it out.

    I made a function called SubtractHealth. Param 0 picks the enemy, param 1 is the amount of health to subtract and param 2 chooses a new animation frame for the enemy sprite.

    My events in the function look like this:

    Set enemyUID to Function.Param(0)

    Subtract Function.Param(1) from Health

    Set animation frame to Function.Param(2)

    I'm calling the function like this:

    "SubtractHealth" (enemy.UID, 5, 3) which works well.

    But, my issue is that in some cases I don't want to change the animation frame. So I'm trying to call the same function like this:

    "SubtractHealth" (enemy.UID, 5) which is giving me all sorts of problems. I'm not sure how to call it properly.

    EDIT: Just as an aside, I'm using "SubtractHealth" (enemy.UID, 5, enemy.AnimationFrame) as a workaround for this specific example, but I have several other different functions with a similar situation so I'm trying to figure out the correct way to do it, not the workaround way.

  • We dont know how the flow of code you have set up but when i do use parameters i try to seperate them into its own block to draw the parameters. You could for example do If function parameters# is = to 0 then do nothing

    or you could do if parameters# is more then or equal to 1 assuming that you have 0 to be used as default "do not proceed" the action used event.

    This is just a trick know this a sub event cannot run without its parent event...how ever you can have some subevent to fire off while others wont. Keep that in mind.

    I use this trick all the time for certain values to be used. and often time i would use a number 0 to make sure some event doesnt fire off without a requirement to be met . Such as fishing. Default it stays as 0 and there a blank or have a text that says cannot fish but once you have to set to one it will do the fishing think of it like that.

    Also another thing that pretty cool is that the true/false boolean uses 0 for false and 1 for true.

  • You can also use Function.ParamCount to check how many params are sent, and adjust you logic. It's just as valid to do as Gearworkdragon suggests and just use invalid numbers to check if you should interpret that value or not (a frame of -1 is obviously invalid, so skip that code).

  • Ok. I still don't fully understand but I see what both of you are saying so I'll start updating the code again. Thank you.

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