Use function for same event for multiple conditions?

Get help using Construct 2

Post » Fri Feb 06, 2015 6:21 am

Image

I'd like to preferably have an OR operator between the two sub-events so they can both share the same "set animation" action. Should this be done with the function object for tidier coding or is duplication of the action the best way, as I have done so far?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Fri Feb 06, 2015 10:20 am

My suggestion is If it ain't broke, don't fix it.
But if you really want lots and lots of conditions you can use function, but remember to pass object UID into function (with parameter), and then, in function, pick it with "pick by universal ID"
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 10:51 am

So, function is probably a bit overkill for something simple like this? Is there a way of using an Or operator between two sub events?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Fri Feb 06, 2015 11:31 am

razorMonkey wrote:My suggestion is If it ain't broke, don't fix it.
"

what he said unless you are using the free version there id no need to limit your lines don't rack your brains over it
finish the programe and then go back and debug it thats what I'm doing and its working out nicely
B
5
S
1
Posts: 60
Reputation: 495

Post » Fri Feb 06, 2015 11:48 am

Great thing with function is that, if you need to change what it does, you need to do it in only one place, function itself.
For example if you want PlayerObject to do something else than "set animation to Default" now you need to change it in line 36 and in line 37, so on two places. With more conditions it would be more work.

With function, you would need to change it only in that function (conditions will point on that function).
B
12
S
6
G
2
Posts: 99
Reputation: 1,727

Post » Fri Feb 06, 2015 7:38 pm

That's what I was thinking, I'm just surprised that you can't have one action for two separate conditions. In coding, you would just type two consecutive lines with an || between, and then you could have your action as a bracketed line. Is there a reason C2 doesn't use this hierarchy? (as I said, if I'm overlooking anything that COULD do it this way, I do apologise!) Otherwise, yeah, I'll just use Function.
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Fri Feb 06, 2015 7:51 pm

You can enter quite complex conditional expressions. Have you read this: https://www.scirra.com/manual/78/expressions ?
If your vision so exceeds your ability, then look to something closer.
Moderator
B
134
S
30
G
84
Posts: 5,375
Reputation: 58,432

Post » Fri Feb 06, 2015 9:10 pm

zenox98 wrote:You can enter quite complex conditional expressions. Have you read this: https://www.scirra.com/manual/78/expressions ?


Thanks, yes, I've looked into those, but I'm not proficient enough yet to write conditions as expressions, in fact, I'm not sure EXACTLY how I would write, for instance, the conditions that I've used in my image example as expressions. Can it be done?
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Post » Fri Feb 06, 2015 9:25 pm

It would probably look like this :
You do not have the required permissions to view the files attached to this post.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Fri Feb 06, 2015 9:59 pm

Magistross wrote:It would probably look like this :

Wow, that's perfect! Thanks so much for that example, that will help inspire me to tighten other conditions and gives me a really good way of understanding this in greater detail, thanks again everyone!
B
41
S
12
G
14
Posts: 1,117
Reputation: 11,253

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests