How do I Add conditional comparisons to Pick Nearest to?

Get help using Construct 2

Post » Sat Dec 19, 2015 2:39 am

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.
B
5
S
1
Posts: 68
Reputation: 515

Post » Sat Dec 19, 2015 2:49 am

What is the issue with just adding the condition?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 19, 2015 3:16 am

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:
Code: Select all

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>


yes somehow this worked
this one below makes more sense sort of.


Second way:
Code: Select all
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>


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.
B
5
S
1
Posts: 68
Reputation: 515

Post » Sat Dec 19, 2015 6:04 am

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.
B
89
S
30
G
95
Posts: 5,157
Reputation: 63,450

Post » Sat Dec 19, 2015 6:14 am

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.
B
5
S
1
Posts: 68
Reputation: 515


Return to How do I....?

Who is online

Users browsing this forum: luckyrawatlucky, zenox98 and 3 guests