Use function for same event for multiple conditions?

0 favourites
  • 12 posts
From the Asset Store
Be quick and choose the right answer for the shown equation.
  • 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?

  • 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"

  • 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?

  • 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

  • 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).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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.

  • You can enter quite complex conditional expressions. Have you read this: ?

  • You can enter quite complex conditional expressions. Have you read this: ?

    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?

  • It would probably look like this :

  • 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!

  • In the interests of educating myself further, is it possible to use expressions for the keyboard? Here I would need an expression that tests "{if the keyboard space is pressed} OR {keyboard space is held AND the character is landed}"

    Is this particular function possible with expressions? I'd preferably like to keep all four sub event collections of coditions down to just one condition and event (namely, all leading to just one simulate platform jump)

  • I didn't know that construct supported ternary operator (didn't find it in the manual). Other things we should know about construct 2 expressions ?

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