How do I add parameters to a function I create?

Get help using Construct 2

Post » Tue Mar 18, 2014 9:00 pm

I see various tutorials for functions but they seem a bit beyond my reach for understanding how to add my own parameters to a function.

For example, I'd like to be able to create a text object and set its text to whatever I want by using a function like this:
Function SetText("Hello World",0,5)

So "Hello World" is Parameter(0), x-coord is Parameter(1), and y-coord is Parameter(2). But when I've created functions for use in my game I don't know how to go about doing the parameter parts. My functions just end up being "do this, now do that" routines instead of "do [this], now do [that]" which is what I'd like to do instead.

I hope this makes sense.
B
7
S
1
G
1
Posts: 56
Reputation: 732

Post » Tue Mar 18, 2014 9:09 pm

When you call a function you can add parameters. Then in your function use the system expression Function.param(x).
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

Post » Tue Mar 18, 2014 9:11 pm

You dont need to set the params when you create the function.
When you call a function theres a button below the textbox where you write the function name, called "Add parameter".

So you will do something like this:
Function > Call "setTextFunc"(txt, X, Y) ....you will need to add 3 parameters here

Function > On "setTextFunc" > TextBox > Set text to "Function.Param(0)
TextBox > Set position to (Function.Param(1), Function.Param(2)
Please tag me with @caiorosisca if your post is refering to me :). I don't always follow the topics I answer.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

Post » Wed Mar 19, 2014 2:49 pm

Thank you @caiorosisca and @Joskin for your replies on this! This makes much more sense to me, I appreciate you explaining it out in an example like this.
B
7
S
1
G
1
Posts: 56
Reputation: 732


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 21 guests