Creating Expressions

Get help using Construct 2

Post » Sat May 18, 2013 1:51 am

I'm relatively new to Construct 2, so forgive me if I'm just overlooking the obvious.

Is it possible to write expressions in Construct 2? What I mean by that is, write a mathematical expression that returns a true or false value. I've looked around the tutorials on System Conditions, and also System Expressions, but couldn't find what I was looking for.

What I want to be able to do is add a life every time the player gets x amount of points. I was hoping to find a plugin that would allow me to resolve it to an expression, much like you would with an "if" statement;

if(Score % x == 0)
{ ... }

I could do it by storing a counter variable that increases with score, and then once it reaches x, add to score and reset the counter, but it seems a bit convoluted, if I could do the same task without the need for an additional variable.

I'm not sure if what I'm asking is possible. I haven't seen a plugin I can use to write expressions that can resolve to a true or false state. I'm just trying to ensure that I use Construct 2 as efficiently as possible.
B
3
Posts: 23
Reputation: 221

Post » Sat May 18, 2013 1:59 am

you can compare two values in system conditions, and enter the expressions directly
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat May 18, 2013 2:15 am

Yes, that's exactly what I was looking for. I was expecting it to be something I could enter a single expression into, but I imagine the same thing can be achieved by chaining additional logical operators into the second value field.

Got exactly what I needed now. Every time the player scores, I check if the score is exactly divisible by x. If it is, I add a life.

I'm so used to writing code that it's taking me a little time to adjust to the way Construct 2 events work.Nullus2013-05-18 02:16:31
B
3
Posts: 23
Reputation: 221

Post » Sat May 18, 2013 3:06 am

You can also make conditional expressions using operators. Refer to this page of the manual, under Operators.
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Sat May 18, 2013 3:41 am

[QUOTE=7Soul] You can also make conditional expressions using operators. Refer to https://www.scirra.com/manual/78/expressions[/QUOTE]

Yeah, I see that. It's nice to know Construct has the Ternary (conditional) operator, but it's not immediately obvious how you apply it.

Using the manual's example, I would assume that:

First Value: health

Comparison: <

Second Value: 0 | score < 0 ? "Game over!" : "Keep going!".

Is how you would apply the conditional operator using the "Compare two values" plugin.

This is the reason I got stumped to begin with. I don't see why you can't just write it in as a single expression, rather than have to break it up. The syntax would be identical.Nullus2013-05-18 03:42:55
B
3
Posts: 23
Reputation: 221

Post » Sat May 18, 2013 3:59 am

Logical operators return 0 or 1, and this include the = operator (not "=="). So you could do it this way :

First Value: Score % x = 0

Comparison: =

Second value: 1
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Sat May 18, 2013 6:07 am

[QUOTE=Nullus] [QUOTE=7Soul] You can also make conditional expressions using operators. Refer to https://www.scirra.com/manual/78/expressions[/QUOTE]

This is the reason I got stumped to begin with. I don't see why you can't just write it in as a single expression, rather than have to break it up. The syntax would be identical.[/QUOTE]
I think construct classic had this. It'd be pretty cool... sometimes I feel like it would be simpler and easier if I could do it in a line, instead of the 'compare values' dialog
Let me redirect this idea to @Ashley ^^
B
84
S
22
G
15
Posts: 1,039
Reputation: 15,249

Post » Sat May 18, 2013 5:03 pm

[QUOTE=Magistross] Logical operators return 0 or 1, and this include the = operator (not "=="). So you could do it this way :

First Value: Score % x = 0

Comparison: =

Second value: 1[/QUOTE]

I didn't think of doing it that way. I do think it makes the intention look clearer.

@7Soul;

It'd be a much welcome addition. Writing a simple expression should require minimal effort, but having to split the expression does seem a little clunky. It's fine when working with two values, but for longer expressions an "If" Special Condition plugin, where you could type in the entire expression on a single line, would make a lot of sense.

I think what would make it distinct from "Compare two values" would be the ability to write full expressions, instead of continually nesting sub-events. For example;

Score % x == 0 && Health == 0

Because there's not an == operator as far as I'm aware, it's not possible to chain multiple "is equal to" operators. You'd have to nest sub-events.

I'm not saying it's not possible to accomplish the same thing by using "Compare two values", and sub-events, but it's very convoluted for something that could be accomplished with a single event.
B
3
Posts: 23
Reputation: 221

Post » Sat May 18, 2013 11:04 pm

@Nullus

You can add multiple conditions to an event, so:

      Compare Two values: (Score % YourVariable) = 0
      Compare Two values: Health = 0

the conditions are in a "And" Block by default

are your conditions, and you add a action to that single event.Aphrodite2013-05-18 23:16:35
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat May 18, 2013 11:35 pm

[QUOTE=Aphrodite] @Nullus

You can add multiple conditions to an event, so:

      Compare Two values: (Score % YourVariable) = 0
      Compare Two values: Health = 0

the conditions are in a "And" Block by default

are your conditions, and you add a action to that single event.[/QUOTE]

Ah. So the action isn't tied to just the one condition to the right of it? A block of conditions have to all be satified to perform the action?

Does it matter which condition the event is next to?

Edit: Ah. I understand now. They group together and are treated as a single larger event.

Thanks for clearing that up for me.Nullus2013-05-18 23:39:29
B
3
Posts: 23
Reputation: 221

Next

Return to How do I....?

Who is online

Users browsing this forum: fearfulelephants and 25 guests