Can't seem to be able to narrow down a pick condition

Not favoritedFavorited Favorited 0 favourites
From the Asset Store
(Student workbook & certification) Quickly learn how to create Roguelike Adventure IGMs in this online workshop.
  • So I have these two conditions, that pick different tiles relative to their position to the "wall" tiles (blue). As you can see, one picks every tile that is located to the bottom left of a wall tile (in a diagonal) ; and another picks every tile that is located above a wall tile.

    But for the life of me, I can't seem to be able to combine the two in order to only pick the tiles that are bottom left of a wall but none that are above a wall.

    When choosing "not equal" to the second condition, nothing happens. What am I missing here??

    Thanks in advance!!

  • Enabling both conditions doesn’t do it? It should

  • No, unfortunately, it does not... This is the result:

    To explain further my system : I'm using 8 image points on the wall sprite that go in 8 directions of the square (north, north east, east, etc.), and pick ground tiles that "overlap" with those points. Hence the distance expression, picking the closest ground tiles to the wall tiles' image points.

  • So trying it out, the reason it doesn't work is you are picking the tile to the SW of the wall, then trying to pick the tile above that wall. They will never be the same tile, so it doesn't work. Sure the tile could have a wall below it and to the NE, but your logic doesn't check for that.

    Anyways, here is one possible solution with 32x32 tiles. Loop over the tiles instead and check for walls around it. The pick all is so we only need to pick one wall at a time.

  • Ah, thanks a lot for that!

    You seem to have a better handle on my problem, yes.

    I would have never used a "pick all" condition in my case, lol, I'm not even sure I understand how it works. But this approach looks a lot cleaner than mine anyway.

    Here's how it looks on my end:

    The problem is, I want to be able to target this tile (which only has a wall on its north-east side, and no other wall around), but I can't figure how to do it..

    I tried creating a condition where it ignores ground_tiles that have a wall directly under and above them, but I think I don't understand the way Pick All works. It seems counter intuitive to reset the first pick condition... And moreover, as I said, I don't know how to alter your example to achieve the picking I need.

  • The trigger once while true condition doesn’t do anything in a loop.

    Looks like you’d need to check for walls in all 8 directions. Where if a wall is there is just as important as if there isn’t one.

    So you’d basically do this 8 times for each direction… you’d have to accumulate the result in a var somehow.

    Wall: x=tile.x+100
    Wall: y=tile.y-100
    — there is a wall there
    Else
    — there isn’t a wall there

    Maybe this?

    For each tile
    — tile: set neighbors to “”
    — repeat 8 times
    — — wall: x=tile.x+100*round(cos(45*loopindex))
    — — wall: y=tile.y+100*round(sin(45*loopindex))
    — — — tile: add 1 to neighbors
    — — else
    — — — tile: add 0 to neighbors
    
    Tile: neighbors=“00000001”
    — do something

    But that’s ugly. Another approach could be to add all the walls to a 2d array to simplify checking a grid for a tile or not.

    Start of layout:
    — array: set size to (100,100,1)
    —array: clear to 0
    — for each wall
    — — array: set at (int(wall.x/100), int(wall.y/100)) to 1
    
    Var gx=0
    Var gy=0
    
    For each tile
    — set gx to int(wall.x/100)
    — set gy to int(wall.y/100)
    — compare: array.at(gx-1,gy-1)=0
    — compare: array.at(gx,gy-1)=0
    — compare: array.at(gx+1,gy-1)=0
    — compare: array.at(gx-1,gy)=0
    — compare: array.at(gx+1,gy)=0
    — compare: array.at(gx-1,gy+1)=0
    — compare: array.at(gx,gy+1)=0
    — compare: array.at(gx+1,gy+1)=0
    — — do something

    Still pretty verbose. And you’d want the array to be big enough to cover all grid positions, and you’d have to update it if you moved or add/remove walls.

    But we could do better. With an overlap check we could pick all the neighboring walls at once. And the case you’re looking for only has one wall next to the tile and we know what position we’d want that tile to be at.

    For each tile
    Tile: overlaps wall
    Compare: wall.pickedCount=1
    Wall: x=tile.x+100
    Wall: y=tile.y-100
    — do something 

    It extends nicely to other possible cases too. Say you want to check if there are only two walls to the left or right.

    For each tile
    Tile: overlaps wall
    Compare: wall.pickedCount=2
    Wall: x=tile.x-100
    Wall: y=tile.y
    Pick all wall
    Wall: x=tile.x+100
    Wall: y=tile.y
    — do something 
  • Oh my god, this works!! Thank you so much!!

    With your (very simple!!) idea I managed to pick those damn tiles!

    I'm still not sure I understand the "Pick all wall" suggestion you follow up with (I tried it and no tile would be highlighted, but maybe I did it wrong)...

    In any case you're right, it's good if I'm able to categorize tiles by the number of walls they're surrounded with. I guess with your primary system I should be able to create a category for every ground tile's situation.

    Thank you so much for your time!

  • The pick all needs to be in the same event block. You’re using multiple.

    All the conditions in the last example I posted can be in one event block and it’ll work. Most of the conditions can have their own block but this at least has to be grouped in the same block.

    Wall: x=tile.x-100
    Wall: y=tile.y
    Pick all wall
    Wall: x=tile.x+100
    Wall: y=tile.y

    All it does if it’s able to pick the first wall it then tries to pick the second. The pick all makes so it can even pick another wall.

  • I'm sorry, I can't make it to work...

    Doesn't "picked count=1" prevent the conditions to pick another tile?

    Or maybe these precise conditions simply aim to no tile in my grid example and that's where the problem lays?

    Also, I was (finally) making it work with your system, but I don't know how to make the code differentiate beetween those two layouts of walls :

    As you can see, the two tiles with a red cross should behave the same to a player coming onto them: corner of a room, with walls up and left - there will even be cases where the corner is made of just those two walls, without the one in the upper-left diagonal.

    But when coding with the picked count condition, those two tiles won't have the same count (to illustrate this, I marked the walls overlapping those tiles with dots, of a different colour for each tile). Ideally, the code should just get that we have a corner in this direction, without care for the number of walls around this particular corner. I think those cornered tiles should be defined by the fact they have two walls around them, in one of their corner, and not care wether there are any other walls along the walls that form the corner... Not sure if I'm being understandable here...

  • Oh, sorry, I realize my own code was mistaken (the two conditions were the same) ; I corrected this and added an actual case of a tile with only two walls on its sides.

    In this form, it does not do anything (no tile highlighted) :

    But in this form (without the picked.count condition), it does highlight the two tiles that have a wall on their side:

    How could I now differentiate between those two tiles picked ? As the player should not behave the same in both cases.

  • Ok, I managed to do that! But I'm not sure it'll be robust enough for all the cases; do you think I will encounter impossible or contradictory cases? I already noticed putting the block with only 4 coordinates above the one with three yielded different results, so I'm afraid the whole thing will be even more complex to handle once I code for all the possibilities...

  • Well, as I feared, as I went along, it started to break. It looked to work so much at first XD I'm pretty sure I'm not using the Pick all correctly...

    + System: For each tile_ground

    // WALL_UP RIGHT

    ----+ tile_ground: Is overlapping tile_wall

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y-tile_ground.Width

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_up on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_UP"

    --------+ tile_wall: X = tile_ground.X-tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y-tile_ground.Width

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_corner_up_left on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_ANGLE_UP_LEFT"

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y-tile_ground.Width

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X-tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_up_left on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_CORNER_UP_LEFT"

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y-tile_ground.Width

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X+tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_up_right on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_CORNER_UP_RIGHT"

    --------+ tile_wall: X = tile_ground.X-tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y+tile_ground.Width

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_down_left on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_CORNER_DOWN_LEFT"

    --------+ tile_wall: X = tile_ground.X+tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X-tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_corridor_horizontal on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_CORRIDOR_HORIZONTAL"

    --------+ tile_wall: X = tile_ground.X+tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X-tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y+tile_ground.Width

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_deadend_down on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_DEADEND_DOWN"

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y+tile_ground.Width

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X

    --------+ tile_wall: Y = tile_ground.Y-tile_ground.Width

    --------+ System: Pick all tile_wall

    --------+ tile_wall: X = tile_ground.X+tile_ground.Width

    --------+ tile_wall: Y = tile_ground.Y

    ------------+ System: Trigger once

    -------------> tile_ground: Spawn test_target_deadend_right on layer tile_ground.LayerName (image point 0, create hierarchy: False, template: "")

    -------------> tile_ground: Set tile_type to "WALL_DEADEND_RIGHT"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • My bad, it should be comparing the picked count with two in the second example since we are checking two tiles. I edited that post.

    You may just need to work though the logic yourself a bit more. The best solution is one you understand.

  • Thanks a lot!

    It does work with your example, now!

    I'm still having problems with a lot of edge cases where the tile count creates uncertainty about the kind of tile that is supposed to be picked (in particular with cases where the overlap occurs with walls that are located in a diagonal in regards to the tile)... It would be great to have a way to add a "negative" condition (like specifying "there's also no wall in that position"), but it also looks like it's the wrong way to look at the problem, as it will create even more particular cases to describe and think of...

  • How many cases are you trying to handle? All of them?

    If it’s only some then you just need to know the number of wall to compare the pickedCount with and pick each wall in turn separated by pick all.

    You could make a helper function that returns 0 or 1 if a wall is at a location. But then you’d have to use 8 compares to check for each case.

    Or you could do that idea in my second reply that sets a neighbor variable to whether a wall is at each direction or not. For example “00000001” would be a wall to the NE.

    Not super readable but maybe you could modify it to be “NE” instead or maybe “7”.

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