C++ ? syntax, IF/THEN/ELSE shortcut

This forum is currently in read-only mode.
From the Asset Store
Source code, art assets and music tracks to remake this game
  • This is a little complicated, but I think it would assist greatly in making events.

    In C++, the ? is a miniature If/Then/Else statement. The syntax goes like this:

    ( Conditional ? Value if True : Value if False )

    Now, this is not functionality that will allow you to do anything you can't currently do in construct. But it will make it possible to use less sub-events, and make things neater all around.

    Consider the case where you want an enemy to bounce away from you upon an overlap. You can't simply use Family[Behavior].VectorX = -Family[Behavior].VectorX, because there are other events setting it's VectorX. You can't just set Family[Behavior].VectorX = Family[Behavior].VectorX + 100, because what if you're on the other side of the enemy? You'd have to do

    +On Overlap between Player and Family[Behavior].VectorX

    ++Player.Angle = 0

    --Family[Behavior].VectorX = Family[Behavior].VectorX + 100

    ++Player.Angle = 180

    --Family[Behavior].VectorX = Family[Behavior].VectorX - 100

    With the ? functionality, you could merely have:

    +On Overlap between Player and Family[Behavior].VectorX

    -Family[Behavior].VectorX = Family[Behavior].VectorX + ( Player.Angle = 0 ? 100 : -100 )

    Drastically simplifying the event sheet. Well, simplifying it assuming that you know the syntax, but it's not difficult to learn, and it's not like the longhand method of doing the same thing has gone away or anything.

  • So you want something like?

    on collision of sprite a with sprite x

    and sprite x is facing toward sprite a

    sprite a go this way

    then you want

    on collision of sprite a with sprite x

    and sprite x is not facing toward sprite a

    sprite a go another way.

  • Yes.

    Not a high priority feature request or anything, I just think it'd be a nice option to have.

  • Wait... are you talking about simply inverting a condition?

    If so then that functionality is already built in.

    All events are automatically Boolean, and you can right click on the event and invert its condition.

    Of course your still going to need more than one event.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • No, I'm talking about having a consise If/Then/Else statement embedded into an event's action, without requiring an IF/ELSE event.

    Instead of

    +Condition

    ++SubCondition

    --Set Variable to X

    ++Else

    --Set Variable to Y

    you'd have

    +Condition

    -Set Variable to (SubCondition ? X : Y )

    This is the extent of my suggestion. It's simply shorthand.

  • Well one of the things things they try to accomplish is making everything have human readable code, with no real coding experience.

    However once python's back in I'm assuming there's probably some possibility with it.

  • Umm... did you try this? It's already built in, and documented here. It's a little buggy, but I think it works with brackets round each operand, ie. (a = b) ? (c) : (d)

  • That's probably why it didn't work for me... okay!

    Actually, no. It still doesn't work. In fact, it makes my game crash...

  • Hmm, I think I got that to work with the brackets. I can't find the thread or the cap though.

  • I've submitted a bug report to the tracker, as it constantly crashes for me.

  • While you wait for this to be fixed, there's a way to simplify the events by using a different expression:

    +On Overlap between Player and Family[Behavior].VectorX

    -Family[Behavior].VectorX = Family[Behavior].VectorX + ( Cos(Player.Angle) * 100 )

    Haven't had a chance to test it, but I've done something similar before, and it should work.

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