How do I Add conditional comparisons to Pick Nearest to?

0 favourites
  • 5 posts
From the Asset Store
Customize the animation of character when item changed
  • Right now I want something to find something nearest to it, the UID for this object is stored, so its picked already, however, I don't want it to find the nearest of something that doesnt have meet a certain condition.

    How do you usually do this inside of construct 2, I tried using For Each loops but it kept choosing the farthest object or last one made and no longer sorted through them accurately in real time.

  • What is the issue with just adding the condition?

  • I fixed this is two ways just now and they only slightly confuse the crap out of me: (note: both ways include conditional else statements, where before I had no conditional else)

    First way:

    Pick searcher by  UID of searcher>>>
    Check state>>
    Inverted/Not Target varCondition != CorrectCondition>>> (so not not equals.. which means it does equals? I assume)
    Pick nearest to (searcher.X, searcher.Y)>>>>
    <do stuff>
    Else>>>
    Pick searcher by UID of searcher>>>
    Check state>>
    Target varCondition != CorrectCondition>>>
    Pick furthest to (searcher.X, searcher.Y)>>>
    <do same code above>
    [/code:1mbjwe91]
    
    yes somehow this worked
    this one below makes more sense sort of.
    
    Second way:
    [code:1mbjwe91]
    Pick searcher by  UID of searcher>>>
    Check state>>
    Target varCondition == CorrectCondition>>>
    Pick nearest to (searcher.X, searcher.Y)>>>>
    <do stuff>
    Else>>>
    Pick searcher by UID of searcher>>>
    Check state>>
    Target varCondition != CorrectCondition>>>
    <nothing>
    [/code:1mbjwe91]
    
    Of course, placing the "pick furthest" on the else conditional of this one breaks everything so I had to disable it and make it do no action. Which is also what I want.
    Right now though, I'd be more interested in knowing:
    
    A. Why this does nothing or not work the way I want if there is no ELSE, (makes sense code/programming wise of course, but I'm not coding with a scripted language so understanding event list editors is very confusing sometimes as to what can be accepted and what cannot.)
    
    B. with A, why does this not work if I just have one check at the top with If Target == CorrectCondition and just stop at finding the nearest. I assume it will stop at the nearest and check to see if it is correct, and then cease all further searches with things not nearer than that. Which I assume forces you to use the else condition to searcher either farther, or know that the thing you found is not equal to the condition so try the search again?? This is strange concerning the way I have it set up visually and seeing that it does work this way is confusing me somewhat. As in above it (second way) it is showing me looking for something that meets the condition, and then searching nearest to it. When I disable that objects condition intentionally and expect them to stop, they will, but if I spawn other objects meeting the condition farther away from it they will pause and not go farther unless I spawn something closer that does meet the condition,
    
    then I just added a else, and for some reason it works? (especially concerning the second way, where it chooses you if you are not equal and then literally does nothing and knows to choose things farther away) My only reasoning is that, it has picked the object previously that was not meeting the CorrectCondition and knew to disregard it somehow with the previous loop when it looped back over this statement. I have no idea.
  • The "else" isn't needed, and the negated != is a double negative, wouldn't it be easier to just check "="?

    This should work. You pick the searcher instance like you have, then you filter the targets that meet the condition, and pick the closest from them.

    Searcher: pick by uid [something]

    Target: var = [something]

    Target: pick closest to (searcher.x, searcher.y)

    --- do something

    That leverages the picking system. If you want to do it a code way you can just use "for each" and "system compare" (same as a if). You can think of a uid as a pointer.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ok I'll give it a shot.

    That must have been it, the order I tested the '=' since i just removed the else and it worked. Maybe i was accidentally doing something else to it since I just disabled a group of events... weird.

    Thanks.

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