Creating Expressions

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

  • you can compare two values in system conditions, and enter the expressions directly

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

  • You can also make conditional expressions using operators. Refer to this page of the manual, under Operators.

  • You can also make conditional expressions using operators. Refer to scirra.com/manual/78/expressions

    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.

  • Try Construct 3

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

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

  • > You can also make conditional expressions using operators. Refer to scirra.com/manual/78/expressions

    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.

    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 ^^

  • 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

    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.

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

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

    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.

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