Picking two objects

This forum is currently in read-only mode.
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • I have a bunch of sprites, and I'm trying to pick two objects based on the value of one of their variables. The value of the variable, let's call it ID, is different for each sprite. I want to make a condition that will pick two of the sprites, such that if their ID=Value1 OR ID=Value2 they're picked but no other values are picked. It seems like OR does something close to this (e.g. Pick by comparison1 OR Pick by comparison2) however, it doesn't seem to clear previously picked objects the first time.

    What I mean is this:

    I have 2 objects, Object1 and Object2 with two private variables, Var1 and Var2.

    I have 10 Sprites with the private variable ID.

    I have the following code:

    On mouse over Object --->  Call Function Function1 and Remember
    
    On Function 1
         Pick Sprite by Comparison, Sprite.Value('ID')=Object.Value(Var1)
         OR
         Pick Sprite by Comparison, Sprite.Value('ID')=Object.Value(Var2)
                     For Each Sprite --->  DebugText set Text Sprite.Value('ID')[/code:10btf93t]
    
    When I put the mouse over Object1, this works fine and I get the ID of both of the sprites that match
    
    Then, If I put the mouse over Object2, the first time, on top of getting the ID of the two correct sprites, I also get the ID of the sprites that match Object1's variables.  The second time I put the mouse over Object2 I get only the correct two sprites.  This also works in reverse (e.g. if i start with Object2 and then mouseover Object1). 
    
    What's going on?  I can post the cap but literally the only code involved in the function is exactly what I posted above.
  • I guess I should also say that the above is only a step towards another complicated picking goal.

    The end result I want is this:

    The 10 sprites are overlapping each other with some sprites overlapping other sprites. The end goal is that when I mouse over Object1, I pick all sprites that overlap BOTH the sprite that corresponds to Object1.Value('Var1') AND the sprite that corresponds to Object1.Value('Var1'). Those 2 sprites themselves should be excluded from the picked list and only the ones that overlap both of them should be included.

  • [quote:h8vc3r33]What's going on?

    The OR condition has issues.

    Use the "Pick by evaluate" condition and the "or" expression.

    Type something like this for the expression:

    Sprite.Value('foo')=1 or Sprite.Value('foo')=2

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh great, that works, thanks!. Still having trouble figuring out how to use that now to pick the sprites overlapping those two sprites while excluding the two sprites themselves. Any help would be appreciated!

  • [quote:28d59hxy]Still having trouble figuring out how to use that now to pick the sprites overlapping those two sprites while excluding the two sprites themselves.

    Add Sprite to a family such as blue

    Then do something like this:

    + Sprite: Pick by 'foo'=1 or 'foo'=2

    + Sprite: overlaps Blue : offset (0,0)

    + Blue: Pick by 'foo'!=1 and 'foo'!=2

  • So if I implemented this correctly, it seems to be picking sprites overlapping either Sprite1 or Sprite2, whereas I wanted to pick sprites that overlap both Sprite1 and Sprite2 simultaneously. While this picks the union of those sprites, I wanted to pick the intersection. Sorry if that wasn't clear.

    EDIT:

    Just to avoid further confusion, an example is this:

    Sprite1 (corresponding to ID=foo1) overlaps Sprites 5 8 9 and 10

    Sprite2 (corresponding to ID=foo2) overlaps Sprites 3 4 5 and 9

    I want to pick sprites 5 and 9, as they are in both lists.

  • You can use a variable to to achieve that. Pick the sprites around the first selected sprite and set their variable 'select' to 1. Then for the second selected sprite do the same but check if 'select' 1, if it is then that sprite is overlapping both originally selected sprites.

    + Sprite: Value 'foo' Equal to 1

    + Sprite: Sprite overlaps Sprite

    + Sprite: [negated] Sprite: Value 'foo' Equal to 1

    -> Sprite: Set 'select' to 1

    + Sprite: Value 'foo' Equal to 2

    + Sprite: Sprite overlaps Sprite

    + Sprite: [negated] Sprite: Value 'foo' Equal to 2

    + Sprite: Value 'select' Equal to 1

    -> Sprite: Set filter to Black

    You will need to set 'select' back to 0 every time you change what 2 objects are originally selected.

  • Thanks, that worked

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