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

Get help using Construct 2

Post » Fri Jan 13, 2017 9:22 pm

For example, if I call "function" (1,2,3,4,5) but I only want to use parameter 1, 2 and 5
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Fri Jan 13, 2017 9:25 pm

You index the parameters. So you would access Function.Param(0) and Function.Param(1) and Function.Param(4) .
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Fri Jan 13, 2017 9:36 pm

@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.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986

Post » Fri Jan 13, 2017 10:33 pm

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.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Fri Jan 13, 2017 11:01 pm

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).
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Fri Jan 13, 2017 11:36 pm

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.
B
61
S
20
G
56
Posts: 1,077
Reputation: 35,986


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 5 guests