Something that's been bugging me (capx)

0 favourites
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Check out this capx

    It makes 100 randomly placed squares, then 100 randomly placed circles

    then it checks for circles that overlap squares and destroy those circles.

    But the check doesn't work unless I wait a bit before checking. Try with the wait event not disabled.

    This means Construct is executing the check before it creates the objects, unless I put a pause manually.

    Is there a way to force a redraw when it's called? Is there some way I can do this without putting in a pause? If there are nested loops going on this can be a huge pain and prone to mystery bugs with our events.

    If I had 2 requests they would be force redraw and a way to break out of a loop or function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Intuitively if event A is put below another event B... barring some loop or something, one would think event A would happen AFTER event B.

    In Construct, it appears the events kind of happen whenever they want. It seems like the order of actions within a single event happen in order, but this isn't really true either if they have sub events...

    I need some way to tame this wild beast.

  • For example, if you added another On start of layout event at the top level, it would work. Like so:

    Very common gotcha, not documented in the manual at all, but a pretty well known issue. I wish they would add an explanation somewhere in the manual, maybe in the how events works section.

  • Each for loop runs in the same time, it won't wait for one to finish before starting another.

  • I'm pretty sure loops run in their entirety, in order, within the tick it is called before the next frame is drawn... unless specifically broken up to run across multiple frames....

  • Each for loop runs in the same time, it won't wait for one to finish before starting another.

    Perhaps for after startup which I haven't try out.

    But for the rest of the time, my experience is that for loops, they run based on the order from top to down.

  • OP.

    All objects in Construct 2 need one tick before you can call them outside of their own private subevents after creation.

    This is well documented in the official guide which I recommended you to glance through at least once.

    I saw your capx and you could just wait 1 tick.

    If you don't want them to be seen before elimination, just set all of them as invisible on creation and only make the remainders visible after removal is done.

  • Definitely glanced at the official guide once or twice. I'd like to control when a tick happens. Force a tick, if you will. Other engines have a "sync" or "redraw" command for similar reasons. "wait" is tricky if you have nested loops with functions called from them.

    For example if you "wait" within a loop the loop will keep going outside the sub event where the wait takes place thus skipping iterations before deciding to execute the actions after the wait within the loop.



    ====>action 1

    ====>wait 1

    ====>action 2

    it will do the remainder of your loop and action 1s... then do all the action 2s...


    do action 1,


    do action 2,


    as one might expect from any language.

    This is a great feature and it's awesome that it works that way don't get me wrong, but it's not a good substitute for updating when you want it to.

  • Rule is this: you can not pick a newly created object in a condition until the next top level event.

    R0J0hound documented this in a nice way:

    I agree that this should be added to the manual in this way.

    The newly created object is a selected object in the actions following the create action though.

    So all you got to do is make the pick condition part of a new top level event. This is why a second 'on layout' works.

  • Since I have you here... Another common problem is, say you want to then pick all the red squares that are overlapping EACH OTHER and take out any so there is only one red square in any spot (without destroying both or all squares in these cases).

    What's the best practice for A colliding with A?

  • Add a family and put object A inside this family, then using

    On object A collide with family

  • Another issue I had a lot of trouble with in the past.

    Method 1 - use families. Have your object in a family, then for each A, if overlapping with family containing object A, destry A.

    If you are using trial version of C2, you don't have access to families. In that case:

    Method 2 - use UIDs to identify/pick an "active" instance, then pick all and compare if overlapping against that specific instance. You'll also need to use for each in this case, so not all A objects are destroyed at the same time.

  • I like that almost better than families because you have more control of exactly which A you're destroying (or whatever).

  • Actually sorry that was bad advice. In this case, where you are destroying overlapping objects of the same sprite, UID might not work as well. You want to use Pick Nth instance instead:

    [quote:23lxchy3]Pick Nth instance

    Pick the instance at a given place in the internal list of picked objects. This is most useful used in sub-events to act on separate instances. For example, in a "Sprite collided with Sprite" event, Pick 0th instance and Pick 1st instance can be used to act on each instance involved in the collision separately.

    If all objects are currently picked, this condition can also be used to pick an object by its index ID (IID). For more information, see common features.

    You can pick Nth instance and destroy that instance in a loop until the Sprite collided/overlap with Sprite is no longer true (there is only one instance left).

  • With families i do it this way, looping trough the picklist:


    The instances that overlap and have the lowest healtpoints get set opaque, or can be destroyd. A situation that happens a lot.

    Without families and no addon, i have honestly no idea how to do the same. Mayby one day i find a way.

    (Rex could have answerd you that he has an exellent addon for that)

    The thing is. Families are extremely helpfull with picking problems. I understand completely why they are only available in the payed version. Missing families is missing out a huge amount of possibilitys.

    But, almost all beginners have no way to know what they miss. They should make there games according what is possible with the free version. But they have not idea how to do that, and they can not have an idea. One of those things is: do not overlap more then two instances of same object hoping their are conditions to snap those individual overlaps. If you do, you work beyond the limitations of the free version.

    That is my opinion. (means nothing, everyone has one) And mayby there should be some clear document explaining this, when listing up the differences between payed and free. But on the other hand, in my case, i would not have understood that doc, not even after 20 times reading. I would have come to the forum to read how other people solved this. Luckely this community is heaven.

    I cant apologize for my English, i know it is horrible, but i do my best.

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