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

New releases and general discussions.

Post » Mon Jan 26, 2009 6:44 pm

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.
B
2
G
3
Posts: 71
Reputation: 992

Post » Mon Jan 26, 2009 7:18 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Jan 26, 2009 7:20 pm

Yes.

Not a high priority feature request or anything, I just think it'd be a nice option to have.
B
2
G
3
Posts: 71
Reputation: 992

Post » Mon Jan 26, 2009 7:28 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Jan 26, 2009 7:41 pm

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.
B
2
G
3
Posts: 71
Reputation: 992

Post » Mon Jan 26, 2009 7:47 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Mon Jan 26, 2009 8:03 pm

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)
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Jan 26, 2009 8:10 pm

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...
B
2
G
3
Posts: 71
Reputation: 992

Post » Mon Jan 26, 2009 9:56 pm

Hmm, I think I got that to work with the brackets. I can't find the thread or the cap though.
B
3
S
2
G
4
Posts: 271
Reputation: 2,017

Post » Tue Jan 27, 2009 2:54 am

I've submitted a bug report to the tracker, as it constantly crashes for me.
B
2
G
3
Posts: 71
Reputation: 992

Next

Return to Construct Classic Discussion

Who is online

Users browsing this forum: No registered users and 3 guests