How can I create this condition using a single event in Construct 3?

0 favourites
  • 12 posts
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • Coming from using other game engines, I am learning how to use Construct 3 and I find it interesting, but in its event system I find something that really bothers me all the time because I can not develop my logic with enough versatility. With other game engines, I am used to creating these kinds of conditions using a single event:

    Event 1: If (a=1 and b=2) or (c=1 and d=2) then (actions)

    This is something that even the extremely simple and basic game engine called Scratch allows to do easily. However, surprisingly, it seems that with Construct 3 it is not possible to use a single event to create such a condition, but rather I have to use at least 2 events, in this way:

    Event 1: If (a=1 and b=2) then (actions)

    Event 2: If (c=1 and d=2) then (same actions)

    Since I have no idea about javascript, I want to ask: is this an unnecessary restriction of Construct 3, or is it an unavoidable limitation of the javascript language itself?

    Note: I am not looking for workarounds to handle this issue, I am just looking for an answer to my question.

    Regards.

  • You probably want to use Ternary operator to put action based on several criteria under single event like what I do in following case: onicstudios.wordpress.com/2021/02/04/formula-that-moves-object-efficiently

    Try search on forum with keyword 'ternary' so you will end up with relevant topics.

    The most extreme use case I came up with is this one:

    dropbox.com/scl/fi/tj43mky0cinrz7516migo/moving_up.capx

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • alextro Thanks, but that can not be used in many cases. For example, how could this be done using a single event and without having to write javascript code?:

    Event 1: If (Sprite1 is visible and Sprite1 is mirrored) or (Sprite2 is visible and Sprite2 is mirrored), then (actions)

    Here, again, Construct 3 forces me to use two events and repeat the same actions, or use a function for something that I think should be able to be done in a simpler way.

    I really don't understand the reason for these restrictions in the Construct 3 event system.

  • Of course you can put & operator for adding extra condition in expression. For mirrored the expression using width parameter but negative (-width).

  • I was hoping to be able to do at least something similar to this:

    I think this would allow us to create the logic in a much more versatile, easy and fast way.

  • In expression you directly assign value to specific attribute. The comparison can be anything but it needs to be put into a value/property/attribute. works just like if else condition (ternary) even nested one. So yes everything were put in action and you can leave the condition blank or under certain condition.

    https://ibb.co.com/zx36X9D[/img]

    A prove: dropbox.com/scl/fi/vclxylb1wz8yuu8t9ho2n/ternary_and_or.c3p

  • But opacity=0 is not the same as visibility. It's not possible to check visibility in an expression. There is a silly limitation in Construct that expressions can't return boolean result - visible/invisible, enabled/disabled etc.

  • Event 1: If (a=1 and b=2) or (c=1 and d=2) then (actions)

    Hai. This condition, which you have created and which can be generated in most modern programming languages, shows that your solution to the problem is not optimal. Unfortunately, the speed of development is now valued more than the rational use of computing power. That's why modern AAA games are so demanding on resources.

  • Sure not every condition can be passed to expression, yet that some common programming practice can be performed with proper expression writing. Sometimes I want to put complex ternary in one line some other time I'll just do straight event sheeting.

  • I honestly think that the AND/OR operators should be better implemented in Construct so that it would be possible to easily perform all kinds of combinations between them using the visual event system. Also, I think this is something fundamental, since these kinds of operators are something we are using all the time while creating game logic. I am just learning how to use Construct. The first time I wanted to use the OR operator in a single condition within an event and I saw that suddenly all the conditions in the event became OR, I thought "Huh? What is this? what's going on here?", and it is something that I am finding quite restrictive and rigid. In fact, I find it downright strange that a game engine as complete and powerful as Construct offers so little versatility when it comes to using something as fundamental as the AND/OR operators in its event system, to the point that at first I even thought that maybe I didn't know how to find the option to be able to make combinations with them, or maybe it was a limitation of JavaScript language itself. But if JavaScript doesn't have that limitation, I don't know why Construct has it in its event system.

    Hopefully this will improve because I really like Construct in many other aspects.

    Kind regards.

  • But opacity=0 is not the same as visibility. It's not possible to check visibility in an expression. There is a silly limitation in Construct that expressions can't return boolean result - visible/invisible, enabled/disabled etc.

    you can kinda do it by calling a return function passing the uid

    For this overall discussion I haven't really ran into this problem myself. Sub-events or calling the same function/custom-action seems to just work and is arguably cleaner. Still I see how it is a bit rigid.

  • The event system has nothing to do with JavaScript. That’s just what it’s implemented in and actually events do not have a direct correspondence with js.

    If it helps being able to use ors between groups of and’d events has been suggested at least a few times before.

    I think one roadblock is that conditions aren’t just logical, they also deal with picking which leads to some quirky situations.

    Anyways you can largely do what you want to do is just with the system compare or evaluate condition and the and/or expressions (“&”,”|”). But that mostly depends on there being a single instances of the objects you’re comparing and if there’s an expression equivalent to the conditions.

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