Question about condition order and parenting

0 favourites
  • 6 posts
  • I have this situation, where I want to be able to select multiple units like in rts.

    To do this I need an if...else if... loops with if...else if... loop inside (to cover every type of mouse dragging and unit positions). It would be so simple in plain js, but I have no idea how to do this with events. Is it even possible?

    Something like this:

    if(start_x > end_x)
         if(start_x < unit_x+unit_width/2 && ...)
              ...
    else if (...)
         if(...)
    

    How can I do this using events?

    Maybe there is already that functionality (selecting multiple objects) that I don't know about? Or maybe a way to do this without all those if's?

  • You can do ifs, elses, ... and whatever you could do in JS in logic. Example with some comments

    If you're having trouble about picking, it's not exactly the same. By default (when no condition is applied), every object in the layout is picked. After each condition, you select a little more elements, removing from the selected list elements that don't meet the conditions. That means that adding a condition "Ennemy.HP > 0" won't pick ennemy with HP>0 but will remove every ennemy with HP <= 0 from the selected list. This is why there are conditions like "pick all", to add items to the selected list.

    Certain conditions, like "compare 2 values" in the System object, are boolean conditions, and won't be considered as affecting an object type. They will just block an event from triggering if they are false.

    The best way to really understand all the possibilities of this system is to create a sample capx, and try with lots of debug, see what triggers in what cases, find out what the "wait" action can do to the function parameters, discover that removing every object from the selected list will prevent the event from triggering, thus will trigger the else event, ...

    Experimentation is a nice friend here, but there are also lots of things in tutorials ;)

  • mrkujo

    Check out the RTS template.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you for that example, it explained what I wanted.

    I managed to work it out without all the if..else conditions however, and encountered another copy.com/Qt1HWgB0kY0B.

    I still don't understand events well, I'm really new to this.

    I want the last block part to be done even if first two won't happen at all. So the first two parts just switch coords if needed to, and the third part should be done even if nothing was changed in previous blocks, but it doesn't happen. It won't run if first two blocks didn't run. How to do it?

  • Your link takes me to a page "that doesn't exist".

    Please correct the link.

    If it is built upon Guizmus' example, simply add a blank event as event number 6, it will be executed every tick no matter what.

    Without a clear view at what you got though, this advice might be wrong.

    Also don't hesitate to check and re-check how events work if you're still unsure.

  • Not really sure what is wrong with the link, it works when I use it :/

    copy.com/s/Qt1HWgB0kY0B/wrong.png

    I didn't use any example, I'm trying to do very basic thing but I fail to understand how events work.

    To be more clear, I'm trying to do:

    on button release

    if(something) then do something

    if(something) then do something

    do other stuff

    But everything stops after first if, when it is not true, I want it to continue and do second if and stuff after that too no matter if the first if's were true.

    And I don't see any rts template in my templates. Am I missing something?

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