0 Favourites

Why does this 'double pick evaluate' not work?

  • (I don't have enough rep to link my .capx yet. I linked to it from the imgur image instead, so you can get it from there.)

    The dungeon generation algorithm is intended to work like this:

    1) 200 times, generate a new RoomBlueprint. A RoomBlueprint is 128 pixels (two tiles in every direction) larger than the WallBlueprint which represents the room itself, because we want each room to be surrounded by some hallway tiles later. It's OK for hallways to overlap, but not for a room to jut into a hallway (and force it to be narrower than two tiles).

    2) For each new room we make, we pick the RoomBlueprint (the one that is new) and all other WallBlueprints (ones that aren't new).

    3) If our picked RoomBlueprint overlaps any other WallBlueprint or is outside the layout boundaries, then we REJECT and delete it.

    4) Otherwise, we ACCEPT it and set it to no longer being new (and also do a pick all/pick evaluate so that we can select the new WallBlueprint and delete it)

    However, I can't figure this out - The double pick evaluate never runs its sub events, ever, no matter what you try. Notably, if I set the Pick WallBlueprint by evaluating WallBlueprint.NewWall = 0 to = 1 instead, then it immediately works (and of course destroys every new room created, because it's destroyed by the own WallBlueprint it carries) - but this isn't useful for obvious reasons.

    One idea I had was 'maybe if one of the pick evaluates returns an empty pick, it prevents subevents from running'. So I put in an Else event after the double pick evaluate so that the very first room can be set non-new, and then maybe the second room on will have non-new WallBlueprints to compare to so the pick will be non-empty - no luck. It still doesn't run, ever. So that idea was wrong.

    We are going insane. Please help at once. (What I REALLY want to know is why the double pick evaluate never runs as written - because it means there is something I fundamentally don't understand, that I need to learn for future C2 writing.)

  • I'm not sure why you are picking the wallblueprint at all..

    wouldn't an "is overlapping wallblueprint" with the condition wallblueprint.newwall = 0 do the trick?

  • I'm not sure why you are picking the wallblueprint at all..

    wouldn't an "is overlapping wallblueprint" with the condition wallblueprint.newwall = 0 do the trick?

    Good idea, but I tried this and it's also doing nothing:

    Everything gets set non-new but nothing gets destroyed for overlapping, ever.

  • I guess the issue is the picking.

    created instances can't be picked untill the next top level event, if I remember correctly

  • I guess the issue is the picking.

    created instances can't be picked untill the next top level event, if I remember correctly

    That contradicts this:

    If I go back to the original code and change WallBlueprint.NewWall=0 to =1 in the first pick, it correctly picks newly created RoomBlueprint and WallBlueprint pairs, detects that it's overlapping itself and destroys it. So I am definitely picking newly created instances there without waiting for a new top level event to occur first.

    Similarly:

    In the second attempt I posted in the reply, if I set NewWall = 0 to NewWall = 1, it picks the new RoomBlueprint and WallBlueprint, detects that it's overlapping and destroys it, also resulting in new rooms in the same fashion.

    So the ONLY combination that doesn't work is RoomBlueprint being new and WallBlueprint being anything but new. In these cases it NEVER EVER detects the overlap even when it's really obvious, and all rooms are kept alive. And I want to know why these cases are different, because right now I am missing some fundamental knowledge about how C2 works that stops me from seeing this, and it will drive me nuts until I know it.

  • So re-reading your events.

    I assume wallblueprint is in a container with roomblueprint, for you are not creating wallblueprint seperately.

    Ah.. I think I see..

    There is no wallblueprint with newwall=0 within the selection you are picking from.

    You will first have to pick all wallblueprints.

    being that this is a subevent of the event creating the wallblueprint, automatically the just created instance is picked.

    It has newwall=1 so no wallblueprints are picked.

  • Hi, I am also working on this project. On the version I am working on, we have tried that solution (changing the first pick to pick newwall = 1 and it didn't work. We have also tried picking all instances before picking more specific ones and this too fails.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I can see a couple of problems there. There's the picking newly created objects problem and then there's a container picking problem (assuming WallBlueprint is in a container with RoomBlueprint).

    I think what you are trying to do is: you create a room and a wall and then you want to pick the newly created room plus all of the previously created walls and check for overlaps. Right?

    When you create an object, it is picked in that event and any sub-events but you can't pick it through a condition until the next top-level event (except for pick by UID). So, in the first iteration of the loop you create a room and a wall. They are both picked for the rest of the sub-events. In the second iteration, you create a new room and wall. Now those two are picked. The objects created in the previous iteration of the loop are no longer picked and can't be picked again by conditions (except by UID).

    The other problem is that if you pick an object in a container then it picks all the other objects in that container. When you pick a room, its matching wall gets picked and when you pick a wall its matching room is picked. You can't pick them separately. You can't pick just a room from one container instance and the walls from another.

  • I think what you are trying to do is: you create a room and a wall and then you want to pick the newly created room plus all of the previously created walls and check for overlaps. Right?

    Yes, that's correct. We're trying to get it so that the red hallway will only check to see if it is overlapping walls that it was not created with. I am still personally very new at Construct 2 and I'm not asking to have every little thing done, but if you could point towards a solution that would be incredibly helpful!

  • The first problem you can get around by creating all of the objects first in one event and then do the checking in another. Like:

    on start of layout -> create 200 rooms

    on start of layout -> check for overlaps

    For the container picking problem, you can use families. If rooms are in RoomFamily and walls are in WallFamily then picking RoomFamily won't pick the matching walls so you can pick them separately. There are probably other ways to do it like using another sprite that you place on top of a room and check if it is overlapping any other walls (or more than 1 wall?).

  • Thanks a ton! I'll be trying these out later. Really appreciate the help!

  • No problem. Here's an example: createObjectsNoOverlap.capx (r200)

  • Thanks ramones! Your posts helped me a lot to understand how C2 works.

    In a perverse way it's beautiful that the code attempted to be written was fundamentally at odds with how C2 picking works in two completely different ways. XD

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread sticky
4,517 857,169
Tinimations's avatar
Tinimations
Unread sticky
1,586 437,210
matriax's avatar
matriax
Unread hot topic
378 33,250
part12studios's avatar
part12studios